Skip to content

gh-153392: Raise TOMLDecodeError for over-long integers in tomllib#153393

Draft
tonghuaroot wants to merge 2 commits into
python:mainfrom
tonghuaroot:tomllib-int-overlong-tomldecodeerror
Draft

gh-153392: Raise TOMLDecodeError for over-long integers in tomllib#153393
tonghuaroot wants to merge 2 commits into
python:mainfrom
tonghuaroot:tomllib-int-overlong-tomldecodeerror

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

The number branch of tomllib's value parser calls match_to_number without wrapping ValueError, so an integer with more digits than the interpreter's integer string conversion limit escapes tomllib.loads as a bare ValueError instead of tomllib.TOMLDecodeError. The sibling date and time branch already wraps match_to_datetime's ValueError into TOMLDecodeError; this mirrors that for the number branch, so a malformed document raises only TOMLDecodeError, 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_float callback that raises ValueError still propagates unchanged, since that error belongs to the caller and is not a decode error; the existing test_invalid_parse_float contract is preserved.

The regression test in test_error.py forces a low sys.set_int_max_str_digits through test.support.adjust_int_max_str_digits, so it is deterministic and fast; it fails before the change and passes after.

tomllib is vendored from tomli; an upstream sync of the same wrapping is the maintainer's call.

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.
@StanFromIreland StanFromIreland marked this pull request as draft July 9, 2026 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant