Skip to content

Commit 195692b

Browse files
committed
gh-159672: Size keyword replay limits for stdlib modules
1 parent 49017bc commit 195692b

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

‎Lib/test/test_traceback.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,7 @@ def test_keyword_trials_do_not_repeat_warnings(self):
19241924
def test_keyword_replay_requires_complete_valid_input(self):
19251925
for source in ("dell 1", "impor math\nother =", "whille True:\npass",
19261926
"switch +:\n case:", "function f(=):\n pass", "(mat x)",
1927-
"impor math\n" + "pass\n" * 3000):
1927+
"impor math\n" + "pass\n" * 20000):
19281928
with self.subTest(source=source):
19291929
with self.assertRaises(SyntaxError) as caught:
19301930
compile(source, "<test>", "exec")
@@ -1951,13 +1951,13 @@ def test_keyword_trials_do_not_call_normalizer(self):
19511951
@cpython_only
19521952
def test_keyword_replay_source_limit(self):
19531953
with tempfile.TemporaryDirectory() as script_dir:
1954-
for size in (64 * 1024 - 512, 64 * 1024 + 512):
1954+
for size in (256 * 1024 - 512, 256 * 1024 + 512):
19551955
literal = "value = " + repr("a" * size) + "\n"
19561956
for source in (literal + "impor math", "impor math\n" + literal):
19571957
with self.subTest(size=size, typo_first=source.startswith("impor")):
19581958
with self.assertRaises(SyntaxError) as caught:
19591959
compile(source, "<test>", "exec")
1960-
expected = size < 64 * 1024
1960+
expected = size < 256 * 1024
19611961
self.assertEqual(caught.exception._metadata is not None, expected)
19621962
script = make_script(script_dir, "large_keyword_typo", source)
19631963
_, _, stderr = assert_python_failure(script)
@@ -1968,8 +1968,8 @@ def test_keyword_replay_source_limit(self):
19681968
@cpython_only
19691969
def test_keyword_replay_work_limit(self):
19701970
# Several candidates must share the budget, including failed passes.
1971-
for count, expected in ((100, "in"), (300, None)):
1972-
source = "x = 1\n" * count + "for x im seq:\n pass"
1971+
for count, expected in ((100, "lambda"), (2000, None)):
1972+
source = "x = 1\n" * count + "f(" + "fron, " * 8 + "lamda x: x)"
19731973
with self.subTest(count=count), self.assertRaises(SyntaxError) as caught:
19741974
compile(source, "<test>", "exec")
19751975
metadata = caught.exception._metadata

‎Parser/pegen.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ typedef struct {
10821082
} KeywordTypo;
10831083

10841084
#define MAX_KEYWORD_TYPO_CANDIDATES 32
1085-
#define MAX_KEYWORD_TYPO_STEPS 100000
1085+
#define MAX_KEYWORD_TYPO_STEPS 5000000
10861086

10871087
static int
10881088
compare_keyword_typos(const void *a, const void *b)

‎Parser/pegen.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
#define CURRENT_POS (-5)
3131

3232
// Error-only token replay is bounded independently of the source length.
33-
#define MAX_KEYWORD_TYPO_TOKENS 4096
34-
#define MAX_KEYWORD_TYPO_BYTES (64 * 1024)
33+
#define MAX_KEYWORD_TYPO_TOKENS 32768
34+
#define MAX_KEYWORD_TYPO_BYTES (256 * 1024)
3535

3636
typedef struct _memo {
3737
int type;

0 commit comments

Comments
 (0)