Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-140594: Fix an out of bounds read when feeding NUL byte to PyOS_St…
…dioReadline() (GH-140910)

(cherry picked from commit 86a0756)

Co-authored-by: Shamil <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
  • Loading branch information
3 people authored and miss-islington committed Mar 12, 2026
commit 3fd5283dddd0fa7c7c29d07d413853d9fa555e87
8 changes: 8 additions & 0 deletions Lib/test/test_cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ def test_run_module_bug1764407(self):
self.assertTrue(data.find(b'1 loop') != -1)
self.assertTrue(data.find(b'__main__.Timer') != -1)

@support.cpython_only
def test_null_byte_in_interactive_mode(self):
# gh-140594: Fix an out of bounds read when a single NUL character
# is read from the standard input in interactive mode.
proc = spawn_python('-i')
proc.communicate(b'\x00', timeout=support.SHORT_TIMEOUT)
self.assertEqual(proc.returncode, 0)

def test_relativedir_bug46421(self):
# Test `python -m unittest` with a relative directory beginning with ./
# Note: We have to switch to the project's top module's directory, as per
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix an out of bounds read when a single NUL character is read from the standard input.
Patch by Shamil Abdulaev.
2 changes: 1 addition & 1 deletion Parser/myreadline.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
break;
}
n += strlen(p + n);
} while (p[n-1] != '\n');
} while (n == 0 || p[n-1] != '\n');

pr = (char *)PyMem_RawRealloc(p, n+1);
if (pr == NULL) {
Expand Down
Loading