# HG changeset patch
# User Benjamin Peterson <benjamin@python.org>
# Date 1453357424 28800
# Node ID 985fc64c60d6adffd1138b6cc46df388ca91ca5d
# Parent  7ec954b9fc54448a35b56d271340ba109eb381b9
prevent buffer overflow in get_data (closes #26171)

diff --git a/Modules/zipimport.c b/Modules/zipimport.c
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -895,6 +895,11 @@ get_data(char *archive, PyObject *toc_en
         PyMarshal_ReadShortFromFile(fp);        /* local header size */
     file_offset += l;           /* Start of file data */
 
+    if (data_size > LONG_MAX - 1) {
+        fclose(fp);
+        PyErr_NoMemory();
+        return NULL;
+    }
     raw_data = PyString_FromStringAndSize((char *)NULL, compress == 0 ?
                                           data_size : data_size + 1);
     if (raw_data == NULL) {