Commit 0b0e700
committed
Fix SIGSEGV in marshal.loads via self-referencing containers (GHSA-m7gv-g5p9-9qqq)
TYPE_TUPLE, TYPE_LIST, TYPE_DICT, and TYPE_SET used R_REF() to register
containers in p->refs immediately after allocation, before populating
their slots. A crafted payload containing a TYPE_REF back-reference to
the partial container could reach a hashing or iteration site with NULL
slots, causing tuplehash/PyObject_Hash(NULL) -> SIGSEGV.
Fix: use the existing two-phase r_ref_reserve()/r_ref_insert() pattern
(already used by TYPE_FROZENSET, TYPE_CODE, and TYPE_SLICE) for all
four container types. r_ref_reserve() places Py_None as a placeholder
in p->refs; the TYPE_REF handler (line 1675) already detects Py_None
and raises ValueError("bad marshal data (invalid reference)"). After
the container is fully populated, r_ref_insert() replaces the
placeholder with the real object.
Includes regression tests for tuple, list, set, and dict self-reference
payloads.1 parent 54607ee commit 0b0e700
2 files changed
+60
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
731 | 731 | | |
732 | 732 | | |
733 | 733 | | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
734 | 780 | | |
735 | 781 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1385 | 1385 | | |
1386 | 1386 | | |
1387 | 1387 | | |
1388 | | - | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
1389 | 1391 | | |
1390 | 1392 | | |
1391 | 1393 | | |
| |||
1400 | 1402 | | |
1401 | 1403 | | |
1402 | 1404 | | |
| 1405 | + | |
1403 | 1406 | | |
1404 | 1407 | | |
1405 | 1408 | | |
| |||
1413 | 1416 | | |
1414 | 1417 | | |
1415 | 1418 | | |
1416 | | - | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
1417 | 1422 | | |
1418 | 1423 | | |
1419 | 1424 | | |
| |||
1427 | 1432 | | |
1428 | 1433 | | |
1429 | 1434 | | |
| 1435 | + | |
1430 | 1436 | | |
1431 | 1437 | | |
1432 | 1438 | | |
1433 | 1439 | | |
1434 | 1440 | | |
1435 | 1441 | | |
1436 | | - | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
1437 | 1445 | | |
1438 | 1446 | | |
1439 | 1447 | | |
| |||
1466 | 1474 | | |
1467 | 1475 | | |
1468 | 1476 | | |
| 1477 | + | |
1469 | 1478 | | |
1470 | 1479 | | |
1471 | 1480 | | |
| |||
1490 | 1499 | | |
1491 | 1500 | | |
1492 | 1501 | | |
1493 | | - | |
1494 | | - | |
1495 | | - | |
1496 | | - | |
1497 | | - | |
1498 | | - | |
| 1502 | + | |
1499 | 1503 | | |
1500 | 1504 | | |
1501 | 1505 | | |
| |||
1520 | 1524 | | |
1521 | 1525 | | |
1522 | 1526 | | |
1523 | | - | |
1524 | | - | |
| 1527 | + | |
1525 | 1528 | | |
1526 | 1529 | | |
1527 | 1530 | | |
| |||
0 commit comments