Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a potential out-of-bounds memory access vulnerability in the ``TYPE_SLICE`` case of the ``r_object`` function in ``marshal.c``. The code now properly checks if ``r_ref_reserve()`` fails before using its return value, preventing crashes or security issues when deserializing malicious marshal data.
13 changes: 11 additions & 2 deletions Python/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,14 @@ r_object(RFILE *p)
Py_ssize_t idx = r_ref_reserve(flag, p);
PyObject *stop = NULL;
PyObject *step = NULL;
PyObject *start = r_object(p);
PyObject *start = NULL;

if (idx < 0 && flag) {
// r_ref_reserve failed
break;
}

start = r_object(p);
if (start == NULL) {
goto cleanup;
}
Expand All @@ -1671,7 +1678,9 @@ r_object(RFILE *p)
goto cleanup;
}
retval = PySlice_New(start, stop, step);
r_ref_insert(retval, idx, flag, p);
if (retval != NULL) {
r_ref_insert(retval, idx, flag, p);
}
cleanup:
Py_XDECREF(start);
Py_XDECREF(stop);
Expand Down
Loading