changeset: 100016:985fc64c60d6 branch: 2.7 parent: 100011:7ec954b9fc54 user: Benjamin Peterson date: Wed Jan 20 22:23:44 2016 -0800 files: Misc/NEWS Modules/zipimport.c description: prevent buffer overflow in get_data (closes #26171) diff -r 7ec954b9fc54 -r 985fc64c60d6 Misc/NEWS --- a/Misc/NEWS Wed Jan 20 22:06:43 2016 -0800 +++ b/Misc/NEWS Wed Jan 20 22:23:44 2016 -0800 @@ -36,6 +36,9 @@ __str__, __trunc__, and __float__ returning instances of subclasses of str, long, and float to subclasses of str, long, and float correspondingly. +- Issue #26171: Fix possible integer overflow and heap corruption in + zipimporter.get_data(). + Library ------- diff -r 7ec954b9fc54 -r 985fc64c60d6 Modules/zipimport.c --- a/Modules/zipimport.c Wed Jan 20 22:06:43 2016 -0800 +++ b/Modules/zipimport.c Wed Jan 20 22:23:44 2016 -0800 @@ -895,6 +895,11 @@ 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) {