Zero-width characters cause unbounded memory use in PyREPL #126685
Labels
3.13
bugs and security fixes
topic-repl
Related to the interactive shell
type-bug
An unexpected behavior, bug, or error
Bug report
Bug description:
Trying to paste zero-width characters (
U+200B
,U+200C
,U+200D
,U+FEFF
) into the new REPL causes it to get stuck and keep allocating memory. Python 3.12 handles them fine.This seems to happen during screen calculation, so the amount of characters needed to reproduce will depend on the number of cells in a terminal emulator window (I got it working with as few as 3 with a big enough zoom, but 100 should be enough).
A table with all of them x100 to copy for convenience:
To reproduce
^C
or a single^\
The culprit seems to be this loop in
Lib/_pyrepl/reader.py:Reader.calc_screen
and itsscreen
/screen_info
appends:cpython/Lib/_pyrepl/reader.py
Lines 388 to 411 in f4e5643
An additional demo
Screen.Recording.2024-11-11.at.13.52.32.mov
CPython versions tested on:
3.12, 3.13, CPython main branch
Operating systems tested on:
Linux, macOS
The text was updated successfully, but these errors were encountered: