summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2011-05-14 22:20:52 (GMT)
committerNadeem Vawda <nadeem.vawda@gmail.com>2011-05-14 22:20:52 (GMT)
commit565d659dcd97af786a2422c36308f453958f4077 (patch)
tree0b9b82876151e2ec7983a20a735207f3690d00eb /Modules
parent95e686686f600e6df18c32a5e808949517655868 (diff)
parent0c3d96ae1dccc081fbc2a8c50ba6e41fbdc384de (diff)
downloadcpython-565d659dcd97af786a2422c36308f453958f4077.zip
cpython-565d659dcd97af786a2422c36308f453958f4077.tar.gz
cpython-565d659dcd97af786a2422c36308f453958f4077.tar.bz2
Merge: #8650: Make zlib.[de]compressobj().[de]compress() 64-bit clean.
Raise an OverflowError if the input data is too large, instead of silently truncating the input and returning an incorrect result.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/zlibmodule.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index fa07739..ba0e59c 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -420,22 +420,26 @@ PyDoc_STRVAR(comp_compress__doc__,
static PyObject *
PyZlib_objcompress(compobject *self, PyObject *args)
{
- int err, inplen;
+ int err;
+ unsigned int inplen;
Py_ssize_t length = DEFAULTALLOC;
- PyObject *RetVal;
+ PyObject *RetVal = NULL;
Py_buffer pinput;
Byte *input;
unsigned long start_total_out;
if (!PyArg_ParseTuple(args, "y*:compress", &pinput))
return NULL;
+ if (pinput.len > UINT_MAX) {
+ PyErr_SetString(PyExc_OverflowError,
+ "Size does not fit in an unsigned int");
+ goto error_outer;
+ }
input = pinput.buf;
inplen = pinput.len;
- if (!(RetVal = PyBytes_FromStringAndSize(NULL, length))) {
- PyBuffer_Release(&pinput);
- return NULL;
- }
+ if (!(RetVal = PyBytes_FromStringAndSize(NULL, length)))
+ goto error_outer;
ENTER_ZLIB(self);
@@ -484,6 +488,7 @@ PyZlib_objcompress(compobject *self, PyObject *args)
error:
LEAVE_ZLIB(self);
+ error_outer:
PyBuffer_Release(&pinput);
return RetVal;
}
@@ -502,9 +507,10 @@ PyDoc_STRVAR(decomp_decompress__doc__,
static PyObject *
PyZlib_objdecompress(compobject *self, PyObject *args)
{
- int err, inplen, max_length = 0;
+ int err, max_length = 0;
+ unsigned int inplen;
Py_ssize_t old_length, length = DEFAULTALLOC;
- PyObject *RetVal;
+ PyObject *RetVal = NULL;
Py_buffer pinput;
Byte *input;
unsigned long start_total_out;
@@ -512,22 +518,24 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "y*|i:decompress", &pinput,
&max_length))
return NULL;
+ if (pinput.len > UINT_MAX) {
+ PyErr_SetString(PyExc_OverflowError,
+ "Size does not fit in an unsigned int");
+ goto error_outer;
+ }
input = pinput.buf;
inplen = pinput.len;
if (max_length < 0) {
- PyBuffer_Release(&pinput);
PyErr_SetString(PyExc_ValueError,
"max_length must be greater than zero");
- return NULL;
+ goto error_outer;
}
/* limit amount of data allocated to max_length */
if (max_length && length > max_length)
length = max_length;
- if (!(RetVal = PyBytes_FromStringAndSize(NULL, length))) {
- PyBuffer_Release(&pinput);
- return NULL;
- }
+ if (!(RetVal = PyBytes_FromStringAndSize(NULL, length)))
+ goto error_outer;
ENTER_ZLIB(self);
@@ -621,6 +629,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
error:
LEAVE_ZLIB(self);
+ error_outer:
PyBuffer_Release(&pinput);
return RetVal;
}