gh-153392: Raise TOMLDecodeError for over-long integers in tomllib#153393
Draft
tonghuaroot wants to merge 2 commits into
Draft
gh-153392: Raise TOMLDecodeError for over-long integers in tomllib#153393tonghuaroot wants to merge 2 commits into
tonghuaroot wants to merge 2 commits into
Conversation
The number branch of tomllib's value parser called match_to_number without wrapping ValueError, so an integer with more digits than the interpreter's integer string conversion limit escaped as a bare ValueError. The date and time branch already wraps ValueError into TOMLDecodeError; do the same for the number branch so tomllib only raises TOMLDecodeError on a malformed document.
Only wrap the integer conversion's ValueError into TOMLDecodeError. A parse_float callback raising ValueError must propagate unchanged, which test_invalid_parse_float asserts.
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 number branch of tomllib's value parser calls
match_to_numberwithout wrappingValueError, so an integer with more digits than the interpreter's integer string conversion limit escapestomllib.loadsas a bareValueErrorinstead oftomllib.TOMLDecodeError. The sibling date and time branch already wrapsmatch_to_datetime'sValueErrorintoTOMLDecodeError; this mirrors that for the number branch, so a malformed document raises onlyTOMLDecodeError, which is what the documentation promises.Positive and negative decimal integers are both affected. Hexadecimal, octal, and binary literals are not, because they bypass the integer string conversion limit.
The wrap is scoped to the integer conversion only. A
parse_floatcallback that raisesValueErrorstill propagates unchanged, since that error belongs to the caller and is not a decode error; the existingtest_invalid_parse_floatcontract is preserved.The regression test in
test_error.pyforces a lowsys.set_int_max_str_digitsthroughtest.support.adjust_int_max_str_digits, so it is deterministic and fast; it fails before the change and passes after.tomllibis vendored fromtomli; an upstream sync of the same wrapping is the maintainer's call.