Skip to content

gh-154848: Enforce frame boundaries in the C unpickler - #154893

Open
serhiy-storchaka wants to merge 3 commits into
python:mainfrom
serhiy-storchaka:pickle-frame-boundary
Open

gh-154848: Enforce frame boundaries in the C unpickler#154893
serhiy-storchaka wants to merge 3 commits into
python:mainfrom
serhiy-storchaka:pickle-frame-boundary

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

The C unpickler did not enforce PEP 3154 frame boundaries: an opcode or its argument could straddle a frame, and a new frame could begin before the previous one ended. Reads simply continued across the boundary.

So pickle.loads() could produce a different object than pickletools.dis() shows for the same bytes — e.g. a pickle that disassembles as a plain BINBYTES but calls builtins.print on load. The pure-Python unpickler already rejects these.

Such reads now raise UnpicklingError, matching the pure-Python implementation, with no overhead on the unframed read path.

The C unpickler did not enforce PEP 3154 frame boundaries: an opcode or its
argument could straddle a frame, and a new frame could begin before the
previous one ended.  Such reads now raise UnpicklingError, as in the pure
Python implementation.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
serhiy-storchaka and others added 2 commits July 30, 2026 09:50
An opcode is a single byte and cannot straddle a frame boundary; only an
argument can.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The tests only use opcodes available in protocol 4 (FRAME being the newest),
so the PROTO header now declares protocol 4 instead of 5.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant