Repository navigation
Accept Infinity and NaN at the end of the buffer - #130
Merged
Merged
Conversation
json_get_number_size and json_parse_number checked offset + strlen < size before matching Infinity and NaN, so a keyword ending exactly at the end of the input was rejected. The dispatcher in json_get_value_size already uses <=, as do true, false and null.
Owner
|
Hah! Great find. |
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.
With
json_parse_flags_allow_inf_and_nan,Infinity,-Infinity,NaNand-NaNfail withjson_parse_error_invalid_number_formatwhen they are the last bytes of the input, while the same value followed by whitespace, or1at the end, parses:-Infinityfoo = NaNfoo = NaN\nThe keyword checks in
json_get_number_size(json.h:1245,:1263) andjson_parse_number(:1980,:1990) useoffset + strlen < size; the dispatcher injson_get_value_size(:1492,:1497) and thetrue/false/nullchecks use<=. This changes the four sites to<=; the last byte read is stilloffset + strlen - 1. Both passes must change together, otherwise sizing and parsing disagree.Tests are added after
rejects_Infinity_decimal_continuation, plus a truncated-Infinit(8-byte array, no terminator) afternan_overrunthat must still fail. The suite passes (1692 tests) in a gcc Debug build with ASan and UBSan; on master the two new end-of-buffer tests fail in every suite. I did not run clang, tcc, MSVC or macOS.Written with AI assistance (Claude); I have reviewed the change.