Follow-up to #66 and #513. Target: exact Bun pin 4982b91e3702094330f3be3883354c52b8c01323.
Status
Implemented in 095f90396, authored and committed by Chris Breuer without coauthors. The commit is integrated in main. This issue remains open for other-platform verification; full compression or whole-suite parity is not claimed.
Implementation
Zlib, Brotli and Zstd now validate bounds/state before pinning input and output backing stores. The slices are resolved again after pinning, and generated cached fields independently keep both JavaScript views alive through GC. Completion unpins and clears the old pending roots before any error/write callback, so a reentrant write retains its own ownership. Output-pin failure unwinds the input pin; shared input/output storage receives balanced pins.
Write-result storage is cached as a JavaScript typed array instead of a raw pointer. Both synchronous and asynchronous completion re-resolve its current backing storage and skip detached or undersized views. The class schema matches the exact pin, and the final binary contains all 18 cache accessors plus the pin/unpin bridge.
Verified on Darwin
- Complete unchanged
zlib.test.js: 378 pass / 2 skip / 0 fail / 434 assertions. - Unchanged
zlib-handle-bounds-check.test.ts: 9 pass / 0 fail / 13 assertions, including detached-writeState coverage. - Unchanged
zlib-onerror-reentrancy.test.ts: 3 pass / 0 fail / 9 assertions. - New cross-codec regression: transfer blocking/release, shared-storage pin balancing, validation and concurrent-write rejection, GC retention during work and collection after completion. 20 consecutive runs pass with JSC exception checks, plus a passing VM-destruction run. The published parent fails the first input-pin assertion.
- 55/55 runtime regression commands pass, including all 24 native regression files, complete spawn and child-process suites.
- Runtime unit suite: 1,819 pass / 19 skip / 0 fail. Native build: 17/17 steps. Focused Pickier and scoped whitespace checks pass.
No upstream test or fixture, assertion, workload or deadline was changed. Skips are excluded from completed parity. Local evidence: zig-out/compression-lifetime-{build-final,unit,regressions,stress,upstream-final}*, compression-lifetime-parent.json, and compression-lifetime-source-integrity.json. Implementation and verification boundaries are documented in docs/docs/NATIVE_RUNTIME_BINDINGS.md.
Historical reproduction
Before this fix, the unchanged full zlib file reported 377 pass / 2 skip / 1 fail / 429 assertions. Its async write buffer lifetime case detached output storage during an in-flight native write. The source audit also identified the stale raw write_result pointer; the pinned bounds suite now verifies its detached-storage path.
Remaining scope
- Port Zlib/Brotli/Zstd async pinning and GC ownership.
- Release old ownership before reentrant callbacks.
- Re-resolve cached write-result storage at completion.
- Verify unchanged lifetime, bounds, reentrancy and full zlib tests plus cross-codec GC/detachment regressions.
- Integrate the published branch.
- Verify Linux/Windows and broader compression coverage.