mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
Issue #12050: zlib.decompressobj().decompress() now clears the unconsumed_tail
attribute when called without a max_length argument.
This commit is contained in:
parent
9b323a521c
commit
0cc4fd9df7
3 changed files with 24 additions and 7 deletions
|
@ -310,6 +310,15 @@ class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
|
||||||
self.assertRaises(ValueError, dco.decompress, "", -1)
|
self.assertRaises(ValueError, dco.decompress, "", -1)
|
||||||
self.assertEqual('', dco.unconsumed_tail)
|
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):
|
def test_flushes(self):
|
||||||
# Test flush() with the various options, using all the
|
# Test flush() with the various options, using all the
|
||||||
# different levels in order to provide more variations.
|
# different levels in order to provide more variations.
|
||||||
|
|
|
@ -80,6 +80,9 @@ Core and Builtins
|
||||||
Library
|
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
|
- 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,
|
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
|
seeking a bit forward, writing, then seeking before the previous write but
|
||||||
|
|
|
@ -535,18 +535,23 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
|
||||||
Py_END_ALLOW_THREADS
|
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) {
|
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);
|
Py_DECREF(self->unconsumed_tail);
|
||||||
self->unconsumed_tail = PyString_FromStringAndSize((char *)self->zst.next_in,
|
self->unconsumed_tail = PyString_FromStringAndSize((char *)self->zst.next_in,
|
||||||
self->zst.avail_in);
|
self->zst.avail_in);
|
||||||
|
}
|
||||||
|
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) {
|
if(!self->unconsumed_tail) {
|
||||||
Py_DECREF(RetVal);
|
Py_DECREF(RetVal);
|
||||||
RetVal = NULL;
|
RetVal = NULL;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* The end of the compressed data has been reached, so set the
|
/* The end of the compressed data has been reached, so set the
|
||||||
unused_data attribute to a string containing the remainder of the
|
unused_data attribute to a string containing the remainder of the
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue