Skip to content

Commit a986734

Browse files
committed
Make the snippets from the fuzzer sweep assert what they check
builtin_str.py expanded a tab to 2**31-1 columns, allocating 2 GiB to observe that the width is accepted; a string with no tab observes the same acceptance without laying anything out. stdlib_array.py caught the refusal of frombytes() on its own exported buffer and passed silently when nothing was raised. stdlib_hashlib.py used a bare `assert False` as its failure branch. Both now say so through the same shapes the other snippets use. stdlib_socket.py also accepts OverflowError from recv() with a size that does not fit the platform's C int. stdlib_threading_current_frames.py indexed the frame chain for "f123" without first asserting it is there. Assisted-by: Claude
1 parent 186b856 commit a986734

5 files changed

Lines changed: 14 additions & 7 deletions

File tree

‎extra_tests/snippets/builtin_str.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,9 @@ def test_huge_width():
909909
assert_raises(MemoryError, lambda meth=meth: getattr("a", meth)(1 << 62))
910910
assert_raises(OverflowError, lambda: "\ta".expandtabs(1 << 62))
911911
assert_raises(OverflowError, lambda: "\ta".expandtabs(2**31))
912-
assert "\ta".expandtabs(2**31 - 1)[-1] == "a"
912+
# The widest tabsize that still fits is accepted. With no tab to expand
913+
# there is nothing to lay out, so the width is never allocated.
914+
assert "a".expandtabs(2**31 - 1) == "a"
913915

914916

915917
test_huge_width()

‎extra_tests/snippets/stdlib_array.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,9 @@ def test_frombytes_of_itself():
169169
try:
170170
a.frombytes(m)
171171
except (BufferError, TypeError):
172+
# Refused either as a resize while exported or as a buffer whose
173+
# items are not bytes; which one comes first is not the point here.
172174
pass
175+
else:
176+
raise AssertionError("frombytes of its own exported buffer should be refused")
173177
del m

‎extra_tests/snippets/stdlib_hashlib.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import _sha1
33
import hashlib
44

5+
from testutils import assert_raises
6+
57
# print(hashlib.md5)
68
h = hashlib.md5()
79
h.update(b"a")
@@ -60,9 +62,5 @@
6062
# a derived key wider than a C int does not fit, and never gets allocated.
6163
# Which OverflowError comes out depends on the width of a C long: where it is
6264
# narrower than the length asked for, converting the argument fails first.
63-
try:
65+
with assert_raises(OverflowError):
6466
hashlib.pbkdf2_hmac("sha256", b"password", b"salt", 1, 2**62)
65-
except OverflowError:
66-
pass
67-
else:
68-
assert False, "expected OverflowError"

‎extra_tests/snippets/stdlib_socket.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@
180180
for bufsize in (2**62, 2**48):
181181
try:
182182
sizes.recv(bufsize)
183-
except (MemoryError, OSError):
183+
except (MemoryError, OSError, OverflowError):
184+
# A size that does not fit the platform's C int is reported while
185+
# converting the argument, before there is anything to reserve.
184186
pass
185187
with assert_raises(ValueError):
186188
sizes.recvfrom(-1)

‎extra_tests/snippets/stdlib_threading_current_frames.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def f123():
9191
chain.append(frame.f_code.co_name)
9292
frame = frame.f_back
9393
assert "g456" in chain, chain
94+
assert "f123" in chain, chain
9495
assert chain.index("g456") < chain.index("f123"), chain
9596
finally:
9697
leave.set()

0 commit comments

Comments
 (0)