Repository navigation
Conversation
The digit_count == longest_digit_count block returned BIGINT_NUMBER for a negative overflow but INVALID_NUMBER for the positive one, so every integer in [2^64, 10^20) was reported as a malformed number. The check above it already returns BIGINT_NUMBER for both signs, which is why 21 digits worked. Fixes simdjson#2791
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.
In the
digit_count == longest_digit_countblock ofparse_number, the negative arm returnsBIGINT_NUMBERon overflow while the positive arm returnsINVALID_NUMBER, so every integer in[2^64, 10^20)comes back as a malformed number. Thedigit_count > longest_digit_countcheck above it already returnsBIGINT_NUMBERfor both signs, which is why 21 digits worked and 20 did not.doc/tape.mduses99999999999999999999as its worked example of a big integer stored on the string tape. That literal is inside the broken window, so the example does not currently work.This changes the positive arm to
BIGINT_NUMBER(src). The// Positive overflow check:comment above that branch already establishes that both cases it covers are overflow, so the only thing in question was which error to report.parse_numberis shared, so this also affects On Demand:get_number()on a positive 20-digit overflow returnedNUMBER_ERRORwhileget_number_type()already reportedbig_integer. That is why one of the tests is in the On Demand suite.Three tests in two files, each of which fails without the one-line change:
tests/dom/big_integer_tests.cpp- the window boundaries2^64and10^20 - 1parse to the expected digit strings undernumber_as_string(true); and default mode returnsBIGINT_ERRORrather thanNUMBER_ERROR.tests/ondemand/ondemand_number_tests.cpp-positive_big_int, mirroring the existingnegative_big_intnext to it.18446744073709551615staying auint64_tis already covered bynormal_numbers_unaffected.One behavior change: with
number_as_stringoff, that range now yieldsBIGINT_ERRORinstead ofNUMBER_ERROR, matching the negative range and 21-digit numbers.This has a second consequence. The bigint returns skip the
is_not_structural_or_whitespace(*p)check that follows them, and the recovery intape_builderrescans the digits without validating the next byte, so trailing garbage is accepted. That is pre-existing on the paths that already returnedBIGINT_NUMBER, and this change extends it to the 20-digit window:number_as_string(true){"v":18446744073709551616x}NUMBER_ERROR{"v":100000000000000000000x}{"v":-18446744073709551616x}Tightening that means validating the tail on all three bigint paths, which is wider than this issue and would reject inputs that parse today. Doing it for only the arm I touched would make it stricter than its siblings. Happy to take it here or separately, whichever you prefer. I have not pinned the current behavior with a test, since I do not think it is the behavior you want.
I compiled and ran
big_integer_tests,basictests,ondemand_number_tests,ondemand_wrong_type_error_testsandondemand_parse_api_testsagainst this change; all pass. I leftsingleheader/untouched.As on the issue: investigation and drafting were AI-assisted. I have checked the change and reproduced every measurement above.
Fixes #2791