Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e48cf7e

Browse files
committed
prevent overflow in _Unpickler_Read
1 parent 3be2e54 commit e48cf7e

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ Core and Builtins
8181
Library
8282
-------
8383

84+
- Prevent overflow in _Unpickler_Read.
85+
8486
- Issue #25047: The XML encoding declaration written by Element Tree now
8587
respects the letter case given by the user. This restores the ability to
8688
write encoding names in uppercase like "UTF-8", which worked in Python 2.

Modules/_pickle.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,12 @@ _Unpickler_Read(UnpicklerObject *self, char **s, Py_ssize_t n)
11821182
{
11831183
Py_ssize_t num_read;
11841184

1185+
if (self->next_read_idx > PY_SSIZE_T_MAX - n) {
1186+
PickleState *st = _Pickle_GetGlobalState();
1187+
PyErr_SetString(st->UnpicklingError,
1188+
"read would overflow (invalid bytecode)");
1189+
return -1;
1190+
}
11851191
if (self->next_read_idx + n <= self->input_len) {
11861192
*s = self->input_buffer + self->next_read_idx;
11871193
self->next_read_idx += n;

0 commit comments

Comments
 (0)