gh-148653: Reject hashing incompletely initialized tuples#152321
Closed
vedikatai wants to merge 2 commits into
Closed
gh-148653: Reject hashing incompletely initialized tuples#152321vedikatai wants to merge 2 commits into
vedikatai wants to merge 2 commits into
Conversation
… path set_new() used make_new_set(), which GC-tracked the empty set before set_init() populated it from the iterable. That left the same half-built window the vectorcall path already closed, so concurrent GC / get_objects() could observe an inconsistent set and crash on edge cases. Allocate untracked in set_new() and call _PyObject_GC_TRACK() only after set_init() succeeds (skipping if already tracked for re-init).
marshal.loads can expose a partially filled FLAG_REF tuple via TYPE_REF into a set, which called PyObject_Hash(NULL) and SIGSEGV'd. Guard tuple_hash NULL slots with ValueError instead.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
The following commit authors need to sign the Contributor License Agreement: |
Author
|
Closing: opened against upstream by mistake. Constraint was all public actions on vedikatai only — reopening as draft PRs on vedikatai/cpython. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes python/cpython#148653 (formerly GHSA-m7gv-g5p9-9qqq; PSRT cleared for public):
marshal.loads()SIGSEGV on a 16-byte self-referentialTYPE_TUPLE|FLAG_REFpayload whose nested set element is aTYPE_REFto the incomplete outer tuple.User impact
Deterministic SIGSEGV (
exit -11) on untrusted/malformed marshal data. Documented as insecure against malicious input, but crash is still a robustness bug on 3.9–3.16 labels.Bisect
Long-standing (issue reports crashes on 3.9–3.14+). Not introduced in 3.16.0a0 specifically; full rebuild bisect omitted (would not pin a 3.16-only commit). Root cause:
Python/marshal.cregisters the tuple viaR_REFbefore slots are filled; nested set construction hashes the partial tuple →tuple_hash→PyObject_Hash(NULL).Prior attempt: closed PR #148652 (two-phase
r_ref_reserve/r_ref_insert). Locally that approach fixed the crash but failed recursivetest_marshalcases. This PR uses a narrower guard intuple_hashinstead.Diff
Objects/tupleobject.c— ifitem[i] == NULLintuple_hash, raiseValueError(~8 lines C, well under 50-line budget).Test results (3.16.0a0)
Reproducer:
CPython tests:
./python.exe -m test test_marshal test_tuple -q→ SUCCESS (recursive marshal structures preserved).Audit provenance
/tmp/cpython-regression-audit.md.