Skip to content

gh-148653: Forbid marshalling recursive tuples - #155903

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-148653-recursive-tuples
Open

gh-148653: Forbid marshalling recursive tuples#155903
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-148653-recursive-tuples

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Aug 16, 2026

Copy link
Copy Markdown
Member

Unmarshalling data which encodes a self-referencing tuple crashed the interpreter if the reference was hashed while the tuple was still incomplete (e.g. ({<R>: None},)). The tuple is now registered for back-references only after all its items are read, like for frozensets, so such data is rejected with ValueError: bad marshal data (invalid reference).

Marshalling a recursive tuple now raises ValueError, like for recursive code objects, slices and frozendicts (#148698). As a consequence, data which encodes a recursive tuple can no longer be loaded.

Marshalled output is unchanged: dumping 156 stdlib modules at versions 5 and 6 gives identical bytes, and load and dump timings are unchanged.

Also fix a crash when unmarshalling a self-referencing tuple.

Co-Authored-By: Michael Bommarito <michael.bommarito@gmail.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant