fix: enforce max_string_length on JSON number lexemes - #35
Merged
Conversation
Fractional digit runs appended to the from_chars lexeme buffer with no cap, so "0." + huge digit payloads could grow without bound after #34. Route number-token appends through the string-length budget; add a small custom-limit regression. Co-authored-by: Kaius Ruokonen <ruoka@users.noreply.github.com>
ruoka
marked this pull request as ready for review
August 1, 2026 14:31
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.
Bug and impact
After the
std::from_charsnumber rewrite (#34), JSON number lexemes are buffered inm_number_token. Fractional digit runs appended to that buffer with no length cap, so a payload like0.followed by a huge digit run could grow memory without bound and DoS the decoder. Integer overflow already self-limits near ~310 digits via non-finite rejection; fractions did not.Root cause
#34 introduced lexeme buffering for correctly rounded parsing, but only strings (#24) and arrays (#25) were covered by existing DoS budgets. Number-token
push_backpaths (especiallyfractions) had no check againstm_max_string_length.Fix
Route all number-token appends through
append_number_char(), which rejects whenm_number_token.size() >= m_max_string_length(same overridable budget as strings).Validation
NumberLengthLimitAppliesToLexeme(tiny custom limit)./tools/CB.sh debug test --tags='\[xson\]'— 434/434 passedNote
Low Risk
Targeted parser hardening that reuses an existing limit; behavior change is rejecting oversized number lexemes that were previously a memory DoS vector.
Overview
Closes a DoS gap in the JSON decoder: after lexeme buffering for
std::from_chars, long fractional runs (e.g.0.plus many digits) could growm_number_tokenwithout a cap, while integer-only overflow paths were already bounded.All number-token appends now go through
append_number_char(), which rejects when the lexeme reachesm_max_string_length(same overridable limit as strings). Regression testNumberLengthLimitAppliesToLexemeuses a tiny decoder limit for integers, fractions, and scientific forms.Reviewed by Cursor Bugbot for commit 6f81e5a. Bugbot is set up for automated code reviews on this repo. Configure here.