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
{{ message }}
Repository navigation
Bytes fields deserialize to a Uint8Array backed by Node's shared Buffer pool (wrong .buffer, cross-value exposure) #29694
Every Bytes value returned by Prisma Client is decoded as a view into Node's shared 8 KB Buffer pool rather than a standalone buffer. For payloads ≤ 4096 bytes (the common case — hashes, tokens, keys, small blobs), Buffer.from(base64) allocates from the process-global pool, and the returned Uint8Array is a view into that pool. So field.buffer is the 8192-byte pool — which contains other decoded Bytes values from other columns/rows/queries — and field.buffer.byteLength (8192) does not equal the value's length.
Two call sites:
packages/client-engine-runtime/src/json-protocol.ts:157-158 — structured query results (runs for every query on every engine).
functiondecodeBytes(v){const{ buffer, byteOffset, byteLength }=Buffer.from(v,'base64')returnnewUint8Array(buffer,byteOffset,byteLength)}consta=decodeBytes(Buffer.from([1,2,3]).toString('base64'))// value from row/column Aconstb=decodeBytes(Buffer.from([9,9,9,9]).toString('base64'))// value from row/column Bconsole.log(a.length,a.buffer.byteLength)// 3 8192console.log(a.buffer===b.buffer)// true — both alias the same poolconsole.log(Array.from(newUint8Array(a.buffer).slice(a.byteOffset,a.byteOffset+16)))// [1,2,3, 0,0,0,0,0, 9,9,9,9, 0,0,0,0] — B's bytes are visible through A.buffer
Expected
Each Bytes field is a standalone Uint8Array whose .buffer.byteLength === .length and which does not expose unrelated values — e.g. new Uint8Array(user.avatar.buffer) should equal user.avatar.
Actual
.buffer is the 8192-byte shared pool, and distinct Bytes values alias the same ArrayBuffer. Any code that reads .buffer — new Uint8Array(x.buffer), new Blob([x.buffer]), crypto.subtle.digest(algo, x.buffer), structured-clone / postMessage, or sending .buffer over the wire — gets oversized/garbage data, and one row's .buffer contains other rows'/queries' decoded Bytes within the same process.
Activity
fix(client): copy Bytes values out of Node's shared Buffer pool on de…
fix(client): copy Bytes values out of Node's shared Buffer pool on de…