Skip to content

Commit 5b96d39

Browse files
authored
gh-151895: Fix marshal.loads() crash on dict reference-tracking failure (GH-151896)
Loading a reference-tracked dictionary dereferenced a NULL pointer when the allocation that registers it for back-references failed under low memory. It now raises MemoryError, matching the tuple and list paths.
1 parent 70fdc96 commit 5b96d39

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed a crash in :func:`marshal.loads` when an allocation failed while
2+
loading a reference-tracked dictionary; it now raises :exc:`MemoryError`.

Python/marshal.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,9 @@ r_object(RFILE *p)
14711471
}
14721472
if (type == TYPE_DICT) {
14731473
R_REF(v);
1474+
if (v == NULL) {
1475+
break;
1476+
}
14741477
}
14751478
else {
14761479
idx = r_ref_reserve(flag, p);

0 commit comments

Comments
 (0)