Skip to content

Commit 323479d

Browse files
committed
gh-144759: Add regression test for NULL pointer arithmetic in lexer
Add test_lexer_buffer_realloc_with_null_start to test_repl.py that exercises the code path where the lexer buffer is reallocated while tok_mode_stack[0] has NULL start/multi_line_start pointers. This triggers _PyLexer_remember_fstring_buffers and verifies the NULL checks prevent undefined behavior.
1 parent f9500a4 commit 323479d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Lib/test/test_repl.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,22 @@ def test_multiline_string_parsing(self):
143143
output = kill_python(p)
144144
self.assertEqual(p.returncode, 0)
145145

146+
@cpython_only
147+
def test_lexer_buffer_realloc_with_null_start(self):
148+
# gh-144759: NULL pointer arithmetic in the lexer when start and
149+
# multi_line_start are NULL (uninitialized in tok_mode_stack[0])
150+
# and the lexer buffer is reallocated while parsing long input.
151+
long_value = "a" * 2000
152+
user_input = dedent(f"""\
153+
x = f'{{{long_value!r}}}'
154+
print(x)
155+
""")
156+
p = spawn_repl()
157+
p.stdin.write(user_input)
158+
output = kill_python(p)
159+
self.assertEqual(p.returncode, 0)
160+
self.assertIn(long_value, output)
161+
146162
def test_close_stdin(self):
147163
user_input = dedent('''
148164
import os

0 commit comments

Comments
 (0)