]> granicus.if.org Git - python/commitdiff
Issue #16411: Fix a bug where zlib.decompressobj().flush() might try to access previo...
authorNadeem Vawda <nadeem.vawda@gmail.com>
Sun, 11 Nov 2012 02:15:32 +0000 (03:15 +0100)
committerNadeem Vawda <nadeem.vawda@gmail.com>
Sun, 11 Nov 2012 02:15:32 +0000 (03:15 +0100)
Patch by Serhiy Storchaka.

Lib/test/test_zlib.py
Misc/NEWS
Modules/zlibmodule.c

index 6d4b2c350eb1ae79472118ea46123a45de0f0f9d..4661c1d6135662f262700c2209d9e0003bcc6f38 100644 (file)
@@ -459,6 +459,18 @@ class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
                 self.assertEqual(dco.unconsumed_tail, b'')
                 self.assertEqual(dco.unused_data, remainder)
 
+    def test_flush_with_freed_input(self):
+        # Issue #16411: decompressor accesses input to last decompress() call
+        # in flush(), even if this object has been freed in the meanwhile.
+        input1 = b'abcdefghijklmnopqrstuvwxyz'
+        input2 = b'QWERTYUIOPASDFGHJKLZXCVBNM'
+        data = zlib.compress(input1)
+        dco = zlib.decompressobj()
+        dco.decompress(data, 1)
+        del data
+        data = zlib.compress(input2)
+        self.assertEqual(dco.flush(), input1[1:])
+
     if hasattr(zlib.compressobj(), "copy"):
         def test_compresscopy(self):
             # Test copying a compression object
index 01517e10f9105094c763a55cd276903381b1420e..ab18f032c5abad74e0a0a1d68ccb4b7ec3565a60 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -159,6 +159,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #16411: Fix a bug where zlib.decompressobj().flush() might try to access
+  previously-freed memory. Patch by Serhiy Storchaka.
+
 - Issue #16357: fix calling accept() on a SSLSocket created through
   SSLContext.wrap_socket().  Original patch by Jeff McNeil.
 
index 6d4aa3a251bdb00c433b395125ec91626b4f4da4..6a772ad622e99017f0289c2b0000bbf089fc931d 100644 (file)
@@ -883,6 +883,8 @@ PyZlib_unflush(compobject *self, PyObject *args)
     ENTER_ZLIB(self);
 
     start_total_out = self->zst.total_out;
+    self->zst.avail_in = PyBytes_GET_SIZE(self->unconsumed_tail);
+    self->zst.next_in = (Byte *)PyBytes_AS_STRING(self->unconsumed_tail);
     self->zst.avail_out = length;
     self->zst.next_out = (Byte *)PyBytes_AS_STRING(retval);