Skip to content

Commit 249565f

Browse files
committed
gh-136053: Memory Safety Issue in marshal.c TYPE_SLICE Case
1 parent c419af9 commit 249565f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Python/marshal.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,7 +1658,14 @@ r_object(RFILE *p)
16581658
Py_ssize_t idx = r_ref_reserve(flag, p);
16591659
PyObject *stop = NULL;
16601660
PyObject *step = NULL;
1661-
PyObject *start = r_object(p);
1661+
PyObject *start = NULL;
1662+
1663+
if (idx < 0 && flag) {
1664+
// r_ref_reserve failed
1665+
break;
1666+
}
1667+
1668+
start = r_object(p);
16621669
if (start == NULL) {
16631670
goto cleanup;
16641671
}
@@ -1671,7 +1678,9 @@ r_object(RFILE *p)
16711678
goto cleanup;
16721679
}
16731680
retval = PySlice_New(start, stop, step);
1674-
r_ref_insert(retval, idx, flag, p);
1681+
if (retval != NULL) {
1682+
r_ref_insert(retval, idx, flag, p);
1683+
}
16751684
cleanup:
16761685
Py_XDECREF(start);
16771686
Py_XDECREF(stop);

0 commit comments

Comments
 (0)