@@ -65,6 +65,23 @@ def test_issue7820(self):
6565 # two bytes in common with the UTF-8 BOM
6666 self .assertRaises (SyntaxError , eval , b'\xef \xbb \x20 ' )
6767
68+ def test_truncated_utf8_at_eof (self ):
69+ # Regression test for https://issues.oss-fuzz.com/issues/451112368
70+ # Truncated multi-byte UTF-8 sequences at end of input caused an
71+ # out-of-bounds read in Parser/tokenizer/helpers.c:valid_utf8().
72+ truncated = [
73+ b'\xc2 ' , # 2-byte lead, missing 1 continuation
74+ b'\xdf ' , # 2-byte lead, missing 1 continuation
75+ b'\xe0 ' , # 3-byte lead, missing 2 continuations
76+ b'\xe0 \xa0 ' , # 3-byte lead, missing 1 continuation
77+ b'\xf0 \x90 ' , # 4-byte lead, missing 2 continuations
78+ b'\xf0 \x90 \x80 ' , # 4-byte lead, missing 1 continuation
79+ b'\xf3 ' , # 4-byte lead, missing 3 (the oss-fuzz reproducer)
80+ ]
81+ for seq in truncated :
82+ with self .subTest (seq = seq ):
83+ self .assertRaises (SyntaxError , compile , seq , '<test>' , 'exec' )
84+
6885 @support .requires_subprocess ()
6986 def test_20731 (self ):
7087 sub = subprocess .Popen ([sys .executable ,
0 commit comments