summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2000-10-09 14:18:10 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2000-10-09 14:18:10 (GMT)
commitd92383102740bd143c5221a519433e64c4c9c498 (patch)
tree1c70fa7a67307d3c98e9e50c4fcd6f175f8f0a20 /Modules
parent46735add5fd292d1c0141aefa23f92814b15cac3 (diff)
downloadcpython-d92383102740bd143c5221a519433e64c4c9c498.zip
cpython-d92383102740bd143c5221a519433e64c4c9c498.tar.gz
cpython-d92383102740bd143c5221a519433e64c4c9c498.tar.bz2
Patch #101810: check whether zst.avail_out is non-zero when getting
a Z_BUF_ERROR while decompressing. If it is, assume that this means the data being decompressed is bad and raise an exception, instead of just assuming that Z_BUF_ERROR always means that more space is required.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/zlibmodule.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index 9416528..cb2a2e5 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -214,7 +214,21 @@ PyZlib_decompress(PyObject *self, PyObject *args)
case(Z_STREAM_END):
break;
case(Z_BUF_ERROR):
- case(Z_OK):
+ /*
+ * If there is at least 1 byte of room according to zst.avail_out
+ * and we get this error, assume that it means zlib cannot
+ * process the inflate call() due to an error in the data.
+ */
+ if (zst.avail_out > 0)
+ {
+ PyErr_Format(ZlibError, "Error %i while decompressing data",
+ err);
+ inflateEnd(&zst);
+ Py_DECREF(result_str);
+ return NULL;
+ }
+ /* fall through */
+ case(Z_OK):
/* need more memory */
if (_PyString_Resize(&result_str, r_strlen << 1) == -1)
{