[Python-checkins] cpython (merge 3.2 -> default): Merge: #12050: zlib.decompressobj().decompress() now clears the unconsumed_tail
nadeem.vawda
python-checkins at python.org
Sat May 14 14:21:45 CEST 2011
http://hg.python.org/cpython/rev/088e5d705171
changeset: 70101:088e5d705171
parent: 70098:ec35f86efb0d
parent: 70100:49c998a88777
user: Nadeem Vawda <nadeem.vawda at gmail.com>
date: Sat May 14 14:19:56 2011 +0200
summary:
Merge: #12050: zlib.decompressobj().decompress() now clears the unconsumed_tail
attribute when called without a max_length argument.
files:
Lib/test/test_zlib.py | 9 +++++++++
Misc/NEWS | 3 +++
Modules/zlibmodule.c | 19 ++++++++++++-------
3 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py
--- a/Lib/test/test_zlib.py
+++ b/Lib/test/test_zlib.py
@@ -360,6 +360,15 @@
self.assertRaises(ValueError, dco.decompress, b"", -1)
self.assertEqual(b'', dco.unconsumed_tail)
+ def test_clear_unconsumed_tail(self):
+ # Issue #12050: calling decompress() without providing max_length
+ # should clear the unconsumed_tail attribute.
+ cdata = b"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, b"")
+
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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -147,6 +147,9 @@
Library
-------
+- Issue #12050: zlib.decompressobj().decompress() now clears the unconsumed_tail
+ attribute when called without a max_length argument.
+
- Issue #12062: 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 still within buffered
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -574,17 +574,22 @@
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 = PyBytes_FromStringAndSize((char *)self->zst.next_in,
self->zst.avail_in);
- if(!self->unconsumed_tail) {
- Py_DECREF(RetVal);
- RetVal = NULL;
- goto error;
- }
+ }
+ else if (PyBytes_GET_SIZE(self->unconsumed_tail) > 0) {
+ /* All of the compressed data was consumed. Clear unconsumed_tail. */
+ Py_DECREF(self->unconsumed_tail);
+ self->unconsumed_tail = PyBytes_FromStringAndSize("", 0);
+ }
+ if (self->unconsumed_tail == NULL) {
+ Py_DECREF(RetVal);
+ RetVal = NULL;
+ goto error;
}
/* The end of the compressed data has been reached, so set the
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list