summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2011-05-14 14:29:07 +0200
committerNadeem Vawda <nadeem.vawda@gmail.com>2011-05-14 14:29:07 +0200
commit0cc4fd9df7e2a6d6a47c20e66c5b22d590c6be51 (patch)
tree1f9553a5b486926d712b24f909bd55222d094724
parent9b323a521c8612093ff1d23b25c4d9809601e1d6 (diff)
downloadcpython-git-0cc4fd9df7e2a6d6a47c20e66c5b22d590c6be51.tar.gz
Issue #12050: zlib.decompressobj().decompress() now clears the unconsumed_tail
attribute when called without a max_length argument.
-rw-r--r--Lib/test/test_zlib.py9
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/zlibmodule.c19
3 files changed, 24 insertions, 7 deletions
diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py
index a003611a7c..7f631437b5 100644
--- a/Lib/test/test_zlib.py
+++ b/Lib/test/test_zlib.py
@@ -310,6 +310,15 @@ class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
self.assertRaises(ValueError, dco.decompress, "", -1)
self.assertEqual('', dco.unconsumed_tail)
+ def test_clear_unconsumed_tail(self):
+ # Issue #12050: calling decompress() without providing max_length
+ # should clear the unconsumed_tail attribute.
+ cdata = "x\x9cKLJ\x06\x00\x02M\x01" # "abc"
+ dco = zlib.decompressobj()
+ ddata = dco.decompress(cdata, 1)
+ ddata += dco.decompress(dco.unconsumed_tail)
+ self.assertEqual(dco.unconsumed_tail, "")
+
def test_flushes(self):
# Test flush() with the various options, using all the
# different levels in order to provide more variations.
diff --git a/Misc/NEWS b/Misc/NEWS
index d9af57c781..a603912a0c 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -80,6 +80,9 @@ Core and Builtins
Library
-------
+- Issue #12050: zlib.decompressobj().decompress() now clears the unconsumed_tail
+ attribute when called without a max_length argument.
+
- Issue #12062: In the `io` module, fix a flushing bug when doing a certain
type of I/O sequence on a file opened in read+write mode (namely: reading,
seeking a bit forward, writing, then seeking before the previous write but
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index 183f01e91a..bd6d6e256b 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -535,17 +535,22 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
Py_END_ALLOW_THREADS
}
- /* Not all of the compressed data could be accommodated in the output buffer
- of specified size. Return the unconsumed tail in an attribute.*/
if(max_length) {
+ /* Not all of the compressed data could be accommodated in a buffer of
+ the specified size. Return the unconsumed tail in an attribute. */
Py_DECREF(self->unconsumed_tail);
self->unconsumed_tail = PyString_FromStringAndSize((char *)self->zst.next_in,
self->zst.avail_in);
- if(!self->unconsumed_tail) {
- Py_DECREF(RetVal);
- RetVal = NULL;
- goto error;
- }
+ }
+ else if (PyString_GET_SIZE(self->unconsumed_tail) > 0) {
+ /* All of the compressed data was consumed. Clear unconsumed_tail. */
+ Py_DECREF(self->unconsumed_tail);
+ self->unconsumed_tail = PyString_FromStringAndSize("", 0);
+ }
+ if(!self->unconsumed_tail) {
+ Py_DECREF(RetVal);
+ RetVal = NULL;
+ goto error;
}
/* The end of the compressed data has been reached, so set the