Skip to content

fix JSON reader splitting numbers at buffer boundaries - #7724

Merged
philrz merged 1 commit into
mainfrom
json-number-split
Nov 25, 2026
Merged

philrz merged 1 commit into
mainfrom
json-number-split

Conversation

@philrz

@philrz philrz commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

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 . or e failed with invalid 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, and null can'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:

$ super -version && seq 1 100000 | super -s -c 'aggregate count(), sum(this)' -
Version: v0.4.0-122-gf7e3eb63d
{count:100001,sum:4999961089}

On this branch, commit ab6af5c:

$ super -version && seq 1 100000 | super -s -c 'aggregate count(), sum(this)' -
Version: v0.4.0-123-gab6af5c66
{count:100000,sum:5000050000}

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

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
@philrz philrz self-assigned this Nov 25, 2026
@philrz
philrz requested a review from a team November 25, 2026 02:04

@mattnibs mattnibs left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate doing this but I don't see another way to fix this.

@philrz
philrz merged commit 9d61820 into main Nov 25, 2026
2 checks passed
@philrz
philrz deleted the json-number-split branch November 25, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0.4.0 read boundary problems at 512k for seq digits

2 participants