Validate number length when coercing StringNode to number - #6232
Merged
cowtowncoder merged 3 commits intoSep 25, 2026
Merged
Conversation
String->BigInteger/BigDecimal/double/float coercion on a StringNode ran through NumberInput without the StreamReadConstraints length check every deserializer applies, so an over-long stringified number reached the O(n^2) Big* parse. Guard the parse the same way as DecimalNode/POJONode (databind#6214).
StringNode to number
Code Review ✅ Approved🟡 Medium risk · StringNode numeric coercions now enforce default limits and change overlong-value results Adds OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
cowtowncoder
approved these changes
Sep 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
StringNodeholding a stringified number coerces toBigInteger,BigDecimal,doubleorfloatthroughNumberInput.parseBigInteger/parseBigDecimal/parseDouble/parseFloat, but unlike the deserializer paths it never applies theStreamReadConstraintsnumber-length check first. The value arrived as a JSON String, so it is bounded only by the max-string-length limit (20MB by default) and not by max-number-length (1000), which meansmapper.readTree(input).get("v").asDecimal()on a multi-megabyte digit string runs the O(n^2)BigDecimal(String)/BigInteger(String)constructors and burns CPU on a single call. I noticed it while checking that the node-level number accessors line up with the guardsBigIntegerDeserializer/BigDecimalDeserializerandStdDeserializeralready apply, and with the scale-side guardDecimalNode/POJONodegained in databind#6214; the String parse path inStringNodewas the one spot still unguarded. The fix follows databind#6214: the strictasBigInteger()/asDecimal()/asDouble()/asFloat()accessors go through the_tryParseAs...helpers, which now callvalidateIntegerLength/validateFPLengthbefore parsing and so surfaceStreamConstraintsException, while the lenient default/Optionalvariants check the length up front and return their default/empty as their contract requires. NoStreamReadConstraintsis available at the node level, so this usesStreamReadConstraints.defaults(), same as the databind#6214 code. Values within the limit coerce exactly as before, and I kept the change insideStringNodeso nothing else moves. Targeting 3.1 since the same code is present on 3.1, 3.2 and 3.x.