diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-11-20 20:53:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-20 20:53:02 (GMT) |
commit | f38164481974a5ca643ec9ae19f118d8ad32353f (patch) | |
tree | f7f9408dc78f1f64b251088dd771ce2508bc6bd4 /Lib | |
parent | 152a437b8dee77fe10f13f504da3ee63f1dd3657 (diff) | |
download | cpython-f38164481974a5ca643ec9ae19f118d8ad32353f.zip cpython-f38164481974a5ca643ec9ae19f118d8ad32353f.tar.gz cpython-f38164481974a5ca643ec9ae19f118d8ad32353f.tar.bz2 |
gh-99581: Fix a buffer overflow in the tokenizer when copying lines that fill the available buffer (GH-99605)
(cherry picked from commit e13d1d9dda8c27691180bc618bd5e9bf43dfa89f)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_tokenize.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py index 47f2c06..63c2501 100644 --- a/Lib/test/test_tokenize.py +++ b/Lib/test/test_tokenize.py @@ -10,6 +10,8 @@ from textwrap import dedent from unittest import TestCase, mock from test.test_grammar import (VALID_UNDERSCORE_LITERALS, INVALID_UNDERSCORE_LITERALS) +from test.support import os_helper +from test.support.script_helper import run_test_script, make_script import os import token @@ -2631,5 +2633,19 @@ async def f(): self.assertEqual(get_tokens(code), get_tokens(code_no_cont)) +class CTokenizerBufferTests(unittest.TestCase): + def test_newline_at_the_end_of_buffer(self): + # See issue 99581: Make sure that if we need to add a new line at the + # end of the buffer, we have enough space in the buffer, specially when + # the current line is as long as the buffer space available. + test_script = f"""\ + #coding: latin-1 + #{"a"*10000} + #{"a"*10002}""" + with os_helper.temp_dir() as temp_dir: + file_name = make_script(temp_dir, 'foo', test_script) + run_test_script(file_name) + + if __name__ == "__main__": unittest.main() |