Commit 4b24214c authored by Benjamin Peterson's avatar Benjamin Peterson

prevent overflow in _Unpickler_Read

parent e9e649cd
...@@ -81,6 +81,8 @@ Core and Builtins ...@@ -81,6 +81,8 @@ Core and Builtins
Library Library
------- -------
- Prevent overflow in _Unpickler_Read.
- Issue #25047: The XML encoding declaration written by Element Tree now - Issue #25047: The XML encoding declaration written by Element Tree now
respects the letter case given by the user. This restores the ability to respects the letter case given by the user. This restores the ability to
write encoding names in uppercase like "UTF-8", which worked in Python 2. write encoding names in uppercase like "UTF-8", which worked in Python 2.
......
...@@ -1182,6 +1182,12 @@ _Unpickler_Read(UnpicklerObject *self, char **s, Py_ssize_t n) ...@@ -1182,6 +1182,12 @@ _Unpickler_Read(UnpicklerObject *self, char **s, Py_ssize_t n)
{ {
Py_ssize_t num_read; Py_ssize_t num_read;
if (self->next_read_idx > PY_SSIZE_T_MAX - n) {
PickleState *st = _Pickle_GetGlobalState();
PyErr_SetString(st->UnpicklingError,
"read would overflow (invalid bytecode)");
return -1;
}
if (self->next_read_idx + n <= self->input_len) { if (self->next_read_idx + n <= self->input_len) {
*s = self->input_buffer + self->next_read_idx; *s = self->input_buffer + self->next_read_idx;
self->next_read_idx += n; self->next_read_idx += n;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment