check from_chars result for integer literals in script parser - #1214
Open
aysha-afrah26 wants to merge 1 commit into
Open
aysha-afrah26 wants to merge 1 commit into
aysha-afrah26 wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
The script parser turns each integer literal into an int64_t with std::from_chars but drops the result, so the one failure the tokenizer can still hand it, result_out_of_range, goes unnoticed. On overflow from_chars leaves the output untouched, which means a literal that does not fit in 64 bits is silently read as 0 instead of being reported. I ran into this with a bitmask: 0xFFFFFFFFFFFFFFFF in a script expression evaluates to 0 rather than all bits set, and 0x8000000000000000 or a long decimal like 99999999999999999999999 behave the same way. These expressions come straight from the XML (Script, preconditions, postconditions) and are compiled at tree build time through ParseScript/ValidateScript, so a tree that looks valid quietly computes with the wrong constant. The fix captures the from_chars result and raises a normal parse error when the literal is out of range, matching how the real-number branch already rejects bad input. Valid literals, including the int64 boundary values, are unchanged, and I added a regression test that fails before the change and passes after.