Repository navigation
fix JSON reader splitting numbers at buffer boundaries - #7724
Merged
Merged
Conversation
The JSON reader returned a value that ended at the end of its 512 KiB input buffer without first reading what came next. A bare number that straddled the boundary was therefore read as two values (89233 became 89 and 233), and a float cut at "." or "e" failed with "invalid JSON value". A number that ends at the end of the buffer now gets more input read before it's returned. Other values end with a closing delimiter or are literals, so they're still returned right away. Fixes #7580
mattnibs
approved these changes
Nov 25, 2026
mattnibs
left a comment
Collaborator
There was a problem hiding this comment.
I hate doing this but I don't see another way to fix this.
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.
The JSON reader reads its input 512 KiB at a time. When a bare number straddled one of those boundaries, the digits before the boundary were returned as a complete value, so integers were silently split in two and floats cut at
.orefailed withinvalid JSON value. This has been the default JSON path since #7161.Now a number that ends exactly at the end of the buffer gets more input read before it's returned. Strings, records, arrays,
true,false, andnullcan't be cut short this way and still parse, so they're returned right away as before, and one that exactly fills the buffer doesn't make the buffer grow.On current tip of
main, commit f7e3eb6:On this branch, commit ab6af5c:
The new ztest and a new Go test of numbers at the end of the buffer both fail on
main. A second Go test checks that a string, record, or array that exactly fills the buffer is returned without growing it, which a ztest can't see. I also checked every split position for each kind of JSON value, in both the native and js/wasm builds. Timings on 10 million bare numbers and on a 468 MB JSON file of GitHub events are unchanged.Fixes #7580