summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2002-05-12 07:19:38 (GMT)
committerTim Peters <tim.peters@gmail.com>2002-05-12 07:19:38 (GMT)
commit39a86c2188b22818c187e860fbf7d77a28a6a116 (patch)
tree3f4ba33fb67e240057bfdb757cbf0343fc076978 /Lib
parent9b1df1db684e5f7f0ab22e423d9858ee5cd340d9 (diff)
downloadcpython-39a86c2188b22818c187e860fbf7d77a28a6a116.zip
cpython-39a86c2188b22818c187e860fbf7d77a28a6a116.tar.gz
cpython-39a86c2188b22818c187e860fbf7d77a28a6a116.tar.bz2
SF bug 555042: zip() may trigger MemoryError.
NOT a bugfix candidate: this is a fix to an optimization introduced in 2.3.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_b2.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/test/test_b2.py b/Lib/test/test_b2.py
index 72810cb..459fd6b 100644
--- a/Lib/test/test_b2.py
+++ b/Lib/test/test_b2.py
@@ -344,7 +344,17 @@ except:
if not exc:
raise TestFailed, 'zip(a, b) - missing expected TypeError'
+# Make sure zip doesn't try to allocate a billion elements for the
+# result list when one of its arguments doesn't say how long it is.
+# A MemoryError is the most likely failure mode.
+class SequenceWithoutALength:
+ def __getitem__(self, i):
+ if i == 5:
+ raise IndexError
+ else:
+ return i
+vereq(zip(SequenceWithoutALength(), xrange(2**30)),
+ list(enumerate(range(5))))
# Epilogue -- unlink the temp file
-
unlink(TESTFN)