Skip to content

int.from_bytes is affected by integer string conversion limitΒ #125573

@nog642

Description

@nog642

Documentation

The documentation here: https://docs.python.org/3/library/stdtypes.html#affected-apis

says that int.from_bytes is not affected by the integer string conversion limit.

The limitations do not apply to functions with a linear algorithm:

However, it seems that it is. I've reproduced this on both 3.10 and 3.12:

Python 3.10.13 (main, Dec 12 2023, 22:43:26) [GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> int.from_bytes(b'\x80'+b'\0'*100000, byteorder='big')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Exceeds the limit (4300) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit
Python 3.12.2 (main, Apr 21 2024, 00:52:02) [GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> int.from_bytes(b'\x80'+b'\0'*100000)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions