You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@theosotr thanks for the clear repro, confirmed and root-caused this.
readObject/writeObject reinterpret the raw Buffer memory directly as a Napi::Reference<Object> (a real C++ object with {env, ref, suppressDestruct} fields), with no check that the bytes at that address actually hold a previously-written reference. Since Buffer.alloc(64, 1) fills the memory with 0x01 bytes, the reinterpreted ref field becomes a bogus non-null "handle," and N-API tries to dereference it, crashing the whole process instead of failing safely. (Zero-filled buffers happened to work by accident, since a null handle short-circuits before touching invalid memory, but nothing actually enforced that requirement.)
I'll tag the memory with a magic marker written by writeObject on first use. readObject now checks for that marker and throws a normal, catchable Error ("Cannot read Object from uninitialized memory") when it's absent, instead of dereferencing untrusted bytes. writeObject on unmarked memory now safely bootstraps a fresh reference in place rather than assuming the existing bytes are valid.
Activity
urbanogilson commentedon Jul 28, 2026
@theosotr thanks for the clear repro, confirmed and root-caused this.
readObject/writeObjectreinterpret the rawBuffermemory directly as aNapi::Reference<Object>(a real C++ object with{env, ref, suppressDestruct}fields), with no check that the bytes at that address actually hold a previously-written reference. SinceBuffer.alloc(64, 1)fills the memory with0x01bytes, the reinterpretedreffield becomes a bogus non-null "handle," and N-API tries to dereference it, crashing the whole process instead of failing safely. (Zero-filled buffers happened to work by accident, since a null handle short-circuits before touching invalid memory, but nothing actually enforced that requirement.)urbanogilson commentedon Jul 28, 2026
I'll tag the memory with a magic marker written by
writeObjecton first use.readObjectnow checks for that marker and throws a normal, catchableError("Cannot read Object from uninitialized memory") when it's absent, instead of dereferencing untrusted bytes.writeObjecton unmarked memory now safely bootstraps a fresh reference in place rather than assuming the existing bytes are valid.Fix SIGSEGV when reading an Object before it's been written (#5) (#6)