ReviewOS

zig-utils/zig-js

Private ABI: seed borrowed-string and heap-snapshot interning

#763
Closed chris opened this 9 days ago ·
9 days ago

Parents: #493, #495 Related: #759, #762

Problem

Private ABI borrowed ZigString views and heap-snapshot string tables still place runtime/host-controlled exact bytes in default-seeded native string maps. Predictable placement lets adversarial property names, URLs, source text, and diagnostic edge names force collision-heavy work at private embedding and heap-inspection boundaries.

Scope

  • Generalize the C/private-ABI lazy secure exact-byte map introduced by #762 so memberships and value maps share one reviewed implementation.
  • Give each context-group borrowed-view store, the mutex-protected context-free borrowed-view store, and each heap-snapshot string table its own lazily installed unpredictable Wyhash context.
  • Keep empty/look-up-only paths entropy- and allocation-free; publish a context only after the first successful native-table mutation.
  • Preserve borrowed-view pointer stability, Latin-1/UTF-16 tagging and ownership, embedded-NUL equality, snapshot string indices/order/schema, and existing OOM/error publication.
  • Make duplicate insertion cleanup and snapshot item/map rollback explicit and leak-free.

No-workaround rules

  • No input/property/depth caps, deterministic fallback seeds, hash-only equality, skipped strings/edges, reordered output, swallowed allocation failure, or weakened ABI lifetime behavior.
  • No stack, queue, job, Promise, Worker, or Map/Set iterator implementation changes.

Acceptance

  • All three private ABI string-map lifetimes use lazy independent secure contexts through one exact-byte primitive.
  • Empty, duplicate, embedded-NUL, non-Latin-1, and 4 KiB cases preserve exact behavior and stable borrowed results.
  • Entropy and allocation failures leave the first mutation unpublished and all owned buffers reclaimed.
  • Focused normal and TSan tests pass with zero leaks/races.
  • Exact-parent private ABI fixtures and relevant heap-snapshot/property-name tests have nonzero accounting and zero regressions.
9 days ago

Implemented and pushed to main in fix(private-abi): seed borrowed string interning (#763). Group/global borrowed views and each heap-snapshot table now use independent lazy secure exact-byte contexts, group access has a leaf lock outside optional API-lock scopes, and all ownership/OOM rollbacks are explicit. Normal/TSan are 7/7; exact-parent private fixtures and 155 relevant Test262 cases show 0 regressions.

9 days ago

Follow-up #764 is complete in fix(strings): randomize intern table placement (#764). The private borrowed-view maps from #763 and the shared InternTable now both avoid predictable attacker-controlled placement, without changing canonical string identity or ABI behavior.

Sign in to comment on this issue.