guard skip_number against end of non-null-terminated input#2637
Closed
uwezkhan wants to merge 1 commit into
Closed
guard skip_number against end of non-null-terminated input#2637uwezkhan wants to merge 1 commit into
uwezkhan wants to merge 1 commit into
Conversation
Owner
|
Thanks for catching this, and apologies for the overlap. This exact fix landed in #2636 (merged earlier today), which guards the same two functions in |
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.
Repro: read a number-valued JSON pointer over a non-null-terminated buffer that ends right after the digits, e.g.
glz::get_view_json<"/h", opts{.null_terminated=false}>over{"h":-0}with no closing brace. ASAN reports a heap-buffer-overflow read of size 1 in skip_number_with_validation.Cause: after scanning the digit run, skip_number and skip_number_with_validation peek at
*itfor a trailing./e/exponent sign without recheckingit != end. The JSON pointer path (parse_value) forces validate_skipped, so it routes through the validating skip. skip_ws only guarantees a byte at the number's start, not after the digits, so a number that ends the buffer over-reads by one byte.Fix: carry null_terminated through skip_number_opts and bound each post-advance peek against end, the same way skip_ws already handles non-null-terminated input. Behavioral difference is only at the buffer edge: before, a number ending at end peeked past it; after, that number is treated as complete and a dangling sign or exponent is a syntax error. The null-terminated path is unchanged and still relies on the trailing sentinel, so there is no cost there.