Skip to content

Structured clone: secure relocation-stable object memoization #859

Description

@chrisbbreuer

Parent: #493
Related: #482, #38, #39, #556, #858

Problem

The structured-clone serializer preserves graph identity with a default AutoHashMapUnmanaged(*Object, u32). JavaScript controls graph size, allocation order, and repeated references, so deterministic raw-pointer placement exposes collision-driven worst-case behavior. Raw addresses also are not the engine relocation identity contract: own-property getters run during serialization and can request collection, while managed object addresses may be rewritten by moving GC.

Scope

  • Replace the raw-pointer memo key with an exact tagged identity: zig-gc stable cell identity for managed objects and lifetime-stable address identity for arena/static objects.
  • Use a per-serialization secure keyed hash context without global state.
  • Keep first insertion failure-atomic: allocation or entropy failure must publish neither a context, a memo entry, nor an object id.
  • Preserve wire pre-order ids, cycles, aliases, DataCloneError behavior, frame limits, SAB token cleanup, and ordinary shallow behavior.
  • Reuse one runtime object-identity definition rather than creating divergent JSON and structured-clone contracts.

No-workaround rules

  • No disabling getters, callbacks, or moving GC.
  • No linear-only visited scan, address secrecy assumption, global visited mark, duplicated object serialization, reduced graph limit, or input blacklist.
  • No change to public structured-clone wire or JavaScript semantics.

Acceptance

  • Default raw-pointer memo is gone; managed identity survives relocation and address identity remains separately tagged.
  • A deterministic default-collision family disperses under a fixed nonzero keyed context.
  • Failed first insertion leaves context, memo, and next_id unpublished; retry succeeds exactly.
  • Cycles and repeated aliases remain exact through getter allocation/collection requests.
  • Focused Debug/TSan, full unit, exact structured-clone conformance, threadfuzz, public C API, and Home private-ABI gates pass with no regressions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions