Skip to content

str(10**10000) hangs if the C _decimal module is missing #118164

Closed
@antonio-rojas

Description

@antonio-rojas

Bug report

Bug description:

The following code

>>> import sys; sys.set_int_max_str_digits(0); 10**10000

works in 3.11 but hangs in 3.12. Interrupting it gives this backtrace:

  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.12/_pylong.py", line 85, in int_to_decimal_string
    return str(int_to_decimal(n))
               ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/_pylong.py", line 77, in int_to_decimal
    result = inner(n, n.bit_length())
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/_pylong.py", line 64, in inner
    return inner(lo, w2) + inner(hi, w - w2) * w2pow(w2)
           ^^^^^^^^^^^^^
  File "/usr/lib/python3.12/_pylong.py", line 64, in inner
    return inner(lo, w2) + inner(hi, w - w2) * w2pow(w2)
           ^^^^^^^^^^^^^
  File "/usr/lib/python3.12/_pylong.py", line 64, in inner
    return inner(lo, w2) + inner(hi, w - w2) * w2pow(w2)
           ^^^^^^^^^^^^^
  [Previous line repeated 6 more times]
  File "/usr/lib/python3.12/_pylong.py", line 45, in w2pow
    result = D2**w
             ~~^^~
  File "/usr/lib/python3.12/_pydecimal.py", line 2339, in __pow__
    ans = self._power_exact(other, context.prec + 1)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/_pydecimal.py", line 2187, in _power_exact
    if xc > 10**p:
            ~~^^~
KeyboardInterrupt

CPython versions tested on:

3.11, 3.12

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions