diff options
Diffstat (limited to 'Lib')
| -rw-r--r-- | Lib/test/crashers/trace_at_recursion_limit.py | 27 | ||||
| -rw-r--r-- | Lib/test/test_cmd_line.py | 12 | ||||
| -rw-r--r-- | Lib/test/test_zlib.py | 13 |
3 files changed, 52 insertions, 0 deletions
diff --git a/Lib/test/crashers/trace_at_recursion_limit.py b/Lib/test/crashers/trace_at_recursion_limit.py new file mode 100644 index 0000000..acd863f --- /dev/null +++ b/Lib/test/crashers/trace_at_recursion_limit.py @@ -0,0 +1,27 @@ +""" +From http://bugs.python.org/issue6717 + +A misbehaving trace hook can trigger a segfault by exceeding the recursion +limit. +""" +import sys + + +def x(): + pass + +def g(*args): + if True: # change to True to crash interpreter + try: + x() + except: + pass + return g + +def f(): + print(sys.getrecursionlimit()) + f() + +sys.settrace(g) + +f() diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index f463af4..7d039ee 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -364,6 +364,18 @@ class CmdLineTest(unittest.TestCase): self.assertEqual(rc, 0) self.assertIn(b'random is 1', out) + def test_del___main__(self): + # Issue #15001: PyRun_SimpleFileExFlags() did crash because it kept a + # borrowed reference to the dict of __main__ module and later modify + # the dict whereas the module was destroyed + filename = test.support.TESTFN + self.addCleanup(test.support.unlink, filename) + with open(filename, "w") as script: + print("import sys", file=script) + print("del sys.modules['__main__']", file=script) + assert_python_ok(filename) + + def test_main(): test.support.run_unittest(CmdLineTest) test.support.reap_children() diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py index 60081e2..c17b4d0 100644 --- a/Lib/test/test_zlib.py +++ b/Lib/test/test_zlib.py @@ -434,6 +434,19 @@ class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase): y += dco.flush() self.assertEqual(y, b'foo') + def test_decompress_unused_data(self): + # Repeated calls to decompress() after EOF should accumulate data in + # dco.unused_data, instead of just storing the arg to the last call. + x = zlib.compress(HAMLET_SCENE) + HAMLET_SCENE + for step in 1, 2, 100: + dco = zlib.decompressobj() + data = b''.join(dco.decompress(x[i : i + step]) + for i in range(0, len(x), step)) + data += dco.flush() + + self.assertEqual(data, HAMLET_SCENE) + self.assertEqual(dco.unused_data, HAMLET_SCENE) + if hasattr(zlib.compressobj(), "copy"): def test_compresscopy(self): # Test copying a compression object |
