Skip to content

json.loads ignores sys.int_max_str_digits (decodes an over-long int instead of raising ValueError) #8051

@myers

Description

@myers

Feature

json.loads should honor the interpreter's integer string-conversion limit (sys.set_int_max_str_digits, PEP 651). RustPython's native _json scanner (the Rust-implemented accelerated module, RustPython's analog of CPython's C _json) decodes an over-long integer literal instead of raising ValueError. The pure-Python decoder already honors the limit (its int conversion goes through int(str)); only the native _json scanner diverges.

Surfaced by running CPython's own stdlib test suite under RustPython — test_json.test_decode::TestCDecode.test_limit_int fails. The minimal standalone reproduction:

Reproduction

import sys, json
sys.set_int_max_str_digits(5000)
json.loads('1' * 5001)

CPython 3.14:

ValueError: Exceeds the limit (5000 digits) for integer string conversion: value has 5001 digits

RustPython:

(returns the 5001-digit integer — no error)

Python Documentation or reference to CPython source code

Suggested fix

Route the integer construction through rustpython_common::int::bytes_to_int with the live vm.state.int_max_str_digits (the same path the int() builtin uses), so the limit is read per-call and sys.set_int_max_str_digits / adjust_int_max_str_digits take effect. Float parsing is unaffected. This also unblocks test_json.test_decode::TestCDecode.test_limit_int.


Investigated and drafted with AI assistance (Claude Code), reviewed by a human before filing, per RustPython's AI policy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-compatA discrepancy between RustPython and CPython

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions