-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Zero-width characters cause unbounded memory use in PyREPL #126685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
3.13
bugs and security fixes
topic-repl
Related to the interactive shell
type-bug
An unexpected behavior, bug, or error
Comments
Excellent find. Needs a backport to 3.13. Gonna fix soon. |
@ambv That's the bug we discussed at Python Łódź, could you please assign me? |
Automatic reproduction for Unix: # gh-126685.py
import os
import signal
from _pyrepl.unix_console import UnixConsole
from typing import Any
from time import sleep
from threading import Thread
mocked_term_width = 8
UnixConsole.getheightwidth = lambda self: (
mocked_term_width,
os.get_terminal_size(self.input_fd)[1],
)
def new_init(self: UnixConsole, /, *args: Any, **kwargs: Any) -> None:
UnixConsole_init(self, *args, **kwargs)
self.input_buffer = b"# " + b"\xe2\x80\x8b" * (mocked_term_width + 1) + b"\nexit\n"
UnixConsole_init = UnixConsole.__init__
UnixConsole.__init__ = new_init
Thread(
target=lambda: sleep(30) or os.kill(os.getpid(), signal.SIGKILL),
daemon=True,
).start() run with
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
3.13
bugs and security fixes
topic-repl
Related to the interactive shell
type-bug
An unexpected behavior, bug, or error
Uh oh!
There was an error while loading. Please reload this page.
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: