Skip to content

gh-111066: Preserve Unpickler memo state on assignment - #162329

Open
Sauvi72 wants to merge 2 commits into
python:mainfrom
Sauvi72:fix/gh-111066-unpickler-memo
Open

Sauvi72 wants to merge 2 commits into
python:mainfrom
Sauvi72:fix/gh-111066-unpickler-memo

Conversation

@Sauvi72

@Sauvi72 Sauvi72 commented Nov 20, 2026 •

Copy link
Copy Markdown

Assigning a dictionary to the C Unpickler's memo populated the old memo and then discarded its array. Copying another unpickler's memo also omitted its sequential index and sparse entries, so continuing a pickle stream could raise UnpicklingError or retrieve stale objects.

Build and validate the replacement memo before installing it, copy the complete state from memo proxies, and install the replacement before releasing the old entries. Include sparse entries in memo snapshots so dictionary-based transfers retain them too. Invalid assignments leave the previous memo intact.

The regression tests cover dictionary and proxy assignments, protocol 4/5 continuation with shared references, sparse indexes, empty and self assignments, rejected keys, independent dictionary copies, and reentrant finalizers.

Fixes #111066.

Validation:

  • Debug build on macOS arm64.
  • test_pickle, test_pickletools, test_copy, test_shelve, test_marshal: 1,865 tests run; 72 skipped; success.
  • 19 memo-related tests with -R 3:3: no reference leaks.
  • Repository pre-commit hooks and patchcheck: passed.
  • Full suite: 51,480 tests run, 17 failures across eight test modules, 3,869 skipped. The failing modules match the earlier unmodified baseline: test_audit, multiprocessing forkserver/spawn test_misc and test_processes, test_os.test_os, test_sys, and test_termios. This environment lacks permissions for some OS/debugger operations and several optional extension dependencies. The full suite is not green locally.

@python-cla-bot

python-cla-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

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.

Assigning a dict to the memo of an Unpickler object fails

1 participant