]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-140576: Fixed crash produced by lexer in case of dedented zero byte (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 29 Oct 2025 13:54:37 +0000 (14:54 +0100)
committerGitHub <noreply@github.com>
Wed, 29 Oct 2025 13:54:37 +0000 (13:54 +0000)
gh-140576: Fixed crash produced by lexer in case of dedented zero byte (GH-140583)
(cherry picked from commit 8706167474e9a625e5f6613d3c7ac77a62faff58)

Co-authored-by: Mikhail Efimov <efimov.mikhail@gmail.com>
Lib/test/test_tokenize.py
Misc/NEWS.d/next/Core_and_Builtins/2025-10-25-17-36-46.gh-issue-140576.kj0SCY.rst [new file with mode: 0644]
Parser/lexer/lexer.c

index d274726eed2e659a33a4246c2e74f0ad09f5c4be..ca67e381958757df73411c716152cd2e77683dc4 100644 (file)
@@ -3183,6 +3183,7 @@ async def f():
             f'__{
                 x:d
             }__'""",
+            " a\n\x00",
         ]:
             with self.subTest(case=case):
                 self.assertRaises(tokenize.TokenError, get_tokens, case)
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-10-25-17-36-46.gh-issue-140576.kj0SCY.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-10-25-17-36-46.gh-issue-140576.kj0SCY.rst
new file mode 100644 (file)
index 0000000..2c27525
--- /dev/null
@@ -0,0 +1,2 @@
+Fixed crash in :func:`tokenize.generate_tokens` in case of
+specific incorrect input. Patch by Mikhail Efimov.
index a69994e9b3d005eb1ee99cbdf17e1e7b21a6ab12..7f25afec302c22564300b9b78437ceb59be8ec91 100644 (file)
@@ -539,6 +539,9 @@ tok_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct t
                     return MAKE_TOKEN(ERRORTOKEN);
                 }
             }
+            else if (c == EOF && PyErr_Occurred()) {
+                return MAKE_TOKEN(ERRORTOKEN);
+            }
             else {
                 break;
             }