[3.13] gh-140576: Fixed crash produced by lexer in case of dedented zero byte (GH-140583) (#140762)

This commit is contained in:
Mikhail Efimov 2025-10-29 17:33:55 +03:00 committed by GitHub
parent 62a3b6b0d9
commit 08cacb2a14
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 0 deletions

View File

@ -3097,6 +3097,7 @@ async def f():
f'__{
x:d
}__'""",
" a\n\x00",
]:
with self.subTest(case=case):
self.assertRaises(tokenize.TokenError, get_tokens, case)

View File

@ -0,0 +1,2 @@
Fixed crash in :func:`tokenize.generate_tokens` in case of
specific incorrect input. Patch by Mikhail Efimov.

View File

@ -481,6 +481,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;
}