Skip to content

guard minified skip_ws against end of non-null-terminated input#2634

Merged
stephenberry merged 2 commits into
stephenberry:mainfrom
uwezkhan:minified-skip-ws-end-guard
Jun 16, 2026
Merged

guard minified skip_ws against end of non-null-terminated input#2634
stephenberry merged 2 commits into
stephenberry:mainfrom
uwezkhan:minified-skip-ws-end-guard

Conversation

@uwezkhan

Copy link
Copy Markdown
Contributor

In minified mode skip_ws returns right away without looking at the iterator, so it never runs the it == end check the non-minified branch does. With a non-null-terminated buffer (null_terminated = false) the JSON object, array, and tuple readers call skip_ws between tokens and then read *it to find the closing brace, bracket, or comma, so a truncated minified document that ends right after a member value reads one byte past the buffer. ASAN flags a heap-buffer-overflow in the object reader for input like {"c":[] (no closing brace) parsed with glz::opts{.null_terminated = false, .minified = true}.

Before, the minified branch of skip_ws was a no-op for every option set. After, it runs the same it == end to end_reached check the non-minified non-null-terminated branch already had, so every reader that leans on skip_ws to bound its next read stays inside the buffer. Putting the check in skip_ws covers the object, array, and tuple readers together instead of guarding each closing-token read separately, and the null-terminated path is untouched since it relies on the trailing sentinel.

uwezkhan and others added 2 commits June 16, 2026 22:38
The early_end !null terminated minified test pops the last byte before its
first read, so it never exercised the complete document. Add an explicit
round-trip of the full buffer for the struct, glz::generic, and glz::skip
readers, pinning that skip_ws's new end_reached return is cleared at depth 0
and does not regress valid input.
@stephenberry stephenberry merged commit 4b026ea into stephenberry:main Jun 16, 2026
52 of 53 checks passed
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.

2 participants