From: Antoine Pitrou Date: Mon, 4 Mar 2013 19:33:36 +0000 (+0100) Subject: Issue #17278: Fix a crash in heapq.heappush() and heapq.heappop() when the list is... X-Git-Tag: v3.3.1rc1~96 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=31584e30ab3e8d01613bb774b1e3d28e73314096;p=thirdparty%2FPython%2Fcpython.git Issue #17278: Fix a crash in heapq.heappush() and heapq.heappop() when the list is being resized concurrently. --- 31584e30ab3e8d01613bb774b1e3d28e73314096 diff --cc Lib/test/test_heapq.py index 54395c074057,20fb89c00084..b48ca6846143 --- a/Lib/test/test_heapq.py +++ b/Lib/test/test_heapq.py @@@ -319,7 -319,18 +319,17 @@@ def L(seqn) return chain(map(lambda x:x, R(Ig(G(seqn))))) + class SideEffectLT: + def __init__(self, value, heap): + self.value = value + self.heap = heap + + def __lt__(self, other): + self.heap[:] = [] + return self.value < other.value + + -class TestErrorHandling(TestCase): - module = None +class TestErrorHandling: def test_non_sequence(self): for f in (self.module.heapify, self.module.heappop): @@@ -369,8 -380,24 +379,24 @@@ self.assertRaises(TypeError, f, 2, N(s)) self.assertRaises(ZeroDivisionError, f, 2, E(s)) + # Issue #17278: the heap may change size while it's being walked. + + def test_heappush_mutating_heap(self): + heap = [] + heap.extend(SideEffectLT(i, heap) for i in range(200)) + # Python version raises IndexError, C version RuntimeError + with self.assertRaises((IndexError, RuntimeError)): + self.module.heappush(heap, SideEffectLT(5, heap)) + + def test_heappop_mutating_heap(self): + heap = [] + heap.extend(SideEffectLT(i, heap) for i in range(200)) + # Python version raises IndexError, C version RuntimeError + with self.assertRaises((IndexError, RuntimeError)): + self.module.heappop(heap) + -class TestErrorHandlingPython(TestErrorHandling): +class TestErrorHandlingPython(TestErrorHandling, TestCase): module = py_heapq @skipUnless(c_heapq, 'requires _heapq') diff --cc Misc/NEWS index 958cc1a7d45e,e9c78b3b31a8..5bc17841cda2 --- a/Misc/NEWS +++ b/Misc/NEWS @@@ -193,9 -233,9 +193,12 @@@ Core and Builtin Library ------- + - Issue #17278: Fix a crash in heapq.heappush() and heapq.heappop() when + the list is being resized concurrently. + +- Issue #16962: Use getdents64 instead of the obsolete getdents syscall + in the subprocess module on Linux. + - Issue #17018: Make Process.join() retry if os.waitpid() fails with EINTR. - Issue #14720: sqlite3: Convert datetime microseconds correctly.