summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2017-09-29 18:34:31 (GMT)
committerBrett Cannon <brettcannon@users.noreply.github.com>2017-09-29 18:34:31 (GMT)
commit01c6a8859ef2ff5545a87cf537573bd342c848bf (patch)
tree67a72ecdad511b4890802ea8c12494f2e3888a58 /Modules
parent66033733aa032707b57cf1b0e8d5a1c5e4afceb9 (diff)
downloadcpython-01c6a8859ef2ff5545a87cf537573bd342c848bf.zip
cpython-01c6a8859ef2ff5545a87cf537573bd342c848bf.tar.gz
cpython-01c6a8859ef2ff5545a87cf537573bd342c848bf.tar.bz2
bpo-31602: Fix an assertion failure in zipimporter.get_source() in case of a bad zlib.decompress() (GH-3784)
While a rare potential failure (it requires swapping out zlib.decompress() itself and forcing it to return a non-bytes object), this change prevents a potential C-level assertion failure and instead substitutes it with an exception. Thanks to Oren Milman for the patch.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/zipimport.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index 141ada5..493e6db 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -1236,6 +1236,14 @@ get_data(PyObject *archive, PyObject *toc_entry)
data = PyObject_CallFunction(decompress, "Oi", raw_data, -15);
Py_DECREF(decompress);
Py_DECREF(raw_data);
+ if (data != NULL && !PyBytes_Check(data)) {
+ PyErr_Format(PyExc_TypeError,
+ "zlib.decompress() must return a bytes object, not "
+ "%.200s",
+ Py_TYPE(data)->tp_name);
+ Py_DECREF(data);
+ return NULL;
+ }
return data;
eof_error: