Skip to content

Commit 6545c58

Browse files
committed
Move the crash regression tests into per-module snippets
crash_regressions.py collected every reproduced crasher in one file. Split it into the snippet for the module each case exercises, and add stdlib_gc.py, stdlib_asyncio.py, stdlib_lzma.py, stdlib_threading_set_repr.py and stdlib_threading_itertools_cycle.py for the cases with no existing home. The suite runs every snippet under the host CPython too, so the checks only RustPython raises are guarded by sys.implementation.name: the hash and __parameters__ recursion depth, and the deque repeat overflow. The float ctypes argument accepts either TypeError or ctypes.ArgumentError. Assisted-by: Claude
1 parent bbe08af commit 6545c58

30 files changed

Lines changed: 483 additions & 417 deletions

‎extra_tests/snippets/builtin_compile.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,8 @@ def _check_flags_error(flags):
145145
assert exc.args[0] == "incomplete input", repr(exc)
146146
else:
147147
raise AssertionError("expected _IncompleteInputError")
148+
149+
# The source is encoded before it is parsed, so a lone surrogate has to be
150+
# reported rather than assumed away.
151+
with assert_raises(UnicodeEncodeError):
152+
compile(chr(0xD800), "<test>", "eval")

‎extra_tests/snippets/builtin_eval.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from testutils import assert_raises
2+
13
assert 3 == eval("1+2")
24

35
code = compile("5+3", "x.py", "eval")
@@ -75,3 +77,8 @@ def make_closure():
7577
assert False, "eval with code containing free variables should fail"
7678
except NameError as e:
7779
pass
80+
81+
# The source is encoded before it is parsed, so a lone surrogate has to be
82+
# reported rather than assumed away.
83+
with assert_raises(UnicodeEncodeError):
84+
eval(chr(0xD800))

‎extra_tests/snippets/builtin_exceptions.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import builtins
2+
import itertools
23
import pickle
34
import platform
45
import sys
@@ -393,3 +394,19 @@ class SubError(MyError):
393394
assert err.exceptions[0].args == ("x",)
394395
else:
395396
assert False, "except* handler did not run"
397+
398+
# The exceptions argument is a sequence, so an arbitrary iterable must be
399+
# rejected rather than drained.
400+
try:
401+
ExceptionGroup("m", itertools.count())
402+
except TypeError:
403+
pass
404+
else:
405+
assert False, "ExceptionGroup accepted an unbounded iterable"
406+
407+
# ImportError.__reduce__ has to cope with the exception carrying no args.
408+
assert pickle.loads(pickle.dumps(ImportError())).args == ()
409+
restored = pickle.loads(pickle.dumps(ImportError("m", name="n", path="p")))
410+
assert restored.args == ("m",)
411+
assert restored.name == "n"
412+
assert restored.path == "p"

‎extra_tests/snippets/builtin_exec.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from testutils import assert_raises
2+
13
exec("def square(x):\n return x * x\n")
24
assert 16 == square(4) # noqa: F821
35

@@ -71,3 +73,8 @@ def f():
7173

7274

7375
f()
76+
77+
# The source is encoded before it is parsed, so a lone surrogate has to be
78+
# reported rather than assumed away.
79+
with assert_raises(UnicodeEncodeError):
80+
exec(chr(0xD800))

‎extra_tests/snippets/builtin_hash.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
from testutils import assert_raises
24

35

@@ -28,3 +30,19 @@ def __hash__(self):
2830

2931
with assert_raises(TypeError):
3032
hash([])
33+
34+
# Hashing a deeply nested tuple must not run off the native stack: the hash
35+
# slot dispatch is what recurses, so that is where the depth is checked.
36+
37+
if sys.implementation.name == "rustpython":
38+
# CPython, which also runs this snippet, survives this depth unguarded.
39+
deep_tuple = ()
40+
for _ in range(sys.getrecursionlimit() * 2):
41+
deep_tuple = (deep_tuple,)
42+
with assert_raises(RecursionError):
43+
hash(deep_tuple)
44+
# a dict key and a set member are hashed on insertion, same dispatch
45+
with assert_raises(RecursionError):
46+
{deep_tuple: 1}
47+
with assert_raises(RecursionError):
48+
{deep_tuple}

‎extra_tests/snippets/builtin_list.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
from testutils import assert_raises
24

35
x = [1, 2, 3]
@@ -923,3 +925,8 @@ def __eq__(self, other):
923925
list1 = rewrite_list_eq([poc()])
924926
list1.remove(list1)
925927
assert list1 == []
928+
929+
# The repeat count is multiplied by the element size; a count that overflows
930+
# that product must raise instead of wrapping into a short allocation.
931+
with assert_raises(MemoryError):
932+
[1] * sys.maxsize

‎extra_tests/snippets/builtin_tuple.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
from testutils import assert_raises
24

35
assert (1, 2) == (1, 2)
@@ -93,3 +95,8 @@ def __eq__(self, x):
9395
assert (float("inf"), float("inf")) >= (float("inf"), float("inf"))
9496
assert not (float("inf"), float("inf")) < (float("inf"), float("inf"))
9597
assert not (float("inf"), float("inf")) > (float("inf"), float("inf"))
98+
99+
# The repeat count is multiplied by the element size; a count that overflows
100+
# that product must raise instead of wrapping into a short allocation.
101+
with assert_raises(MemoryError):
102+
(1,) * sys.maxsize

0 commit comments

Comments
 (0)