Skip to content

Commit d751040

Browse files
committed
Issue python#26171: Prevent buffer overflow in get_data
Backport of 01ddd608b85c.
1 parent 1f0e7c9 commit d751040

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.3.7?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #26171: Fix possible integer overflow and heap corruption in
14+
zipimporter.get_data().
15+
1316
- Issue #25709: Fixed problem with in-place string concatenation and utf-8 cache.
1417

1518
- Issue #24407: Fix crash when dict is mutated while being updated.

Modules/zipimport.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,11 @@ get_data(PyObject *archive, PyObject *toc_entry)
10891089
PyMarshal_ReadShortFromFile(fp); /* local header size */
10901090
file_offset += l; /* Start of file data */
10911091

1092+
if (data_size > LONG_MAX - 1) {
1093+
fclose(fp);
1094+
PyErr_NoMemory();
1095+
return NULL;
1096+
}
10921097
bytes_size = compress == 0 ? data_size : data_size + 1;
10931098
if (bytes_size == 0)
10941099
bytes_size++;

0 commit comments

Comments
 (0)