Skip to content

marshal fails to load a frozendict referenced more than once #155315

Closed

Description

@tonghuaroot

Bug report

marshal cannot round-trip a frozendict that appears more than once in the
data. Loading fails with ValueError, while frozenset in the same shape
works:

>>> import marshal
>>> fd = frozendict({'a': 1, 'b': 2})
>>> marshal.loads(marshal.dumps([fd, fd]))
Traceback (most recent call last):
  ...
ValueError: bad marshal data (invalid reference)
>>> fs = frozenset({1, 2})
>>> marshal.loads(marshal.dumps([fs, fs]))
[frozenset({1, 2}), frozenset({1, 2})]

The reader's TYPE_FROZENDICT branch reserves a back-reference slot with
r_ref_reserve but never fills it with r_ref_insert, unlike TYPE_FROZENSET,
so a later reference to the shared frozendict resolves to an empty slot.

CPython versions tested on:

3.16 (main)

Operating systems tested on:

Linux, macOS

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Aug 7, 2026
  2. added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    and removed on Aug 7, 2026
  3. added
    3.15bugs and security fixes
    3.16new features, bugs and security fixes
    on Aug 16, 2026
  4. added a commit that references this issue on Aug 17, 2026
  5. added a commit that references this issue on Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.15bugs and security fixes3.16new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions