Skip to content

Bytes fields deserialize to a Uint8Array backed by Node's shared Buffer pool (wrong .buffer, cross-value exposure) #29694

Closed

Description

@tsushanth

Description

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).
  • packages/client/src/runtime/utils/deserializeRawResults.ts:20-21 — $queryRaw Bytes columns.
const { buffer, byteOffset, byteLength } = Buffer.from(value, 'base64')
return new Uint8Array(buffer, byteOffset, byteLength)

Steps to reproduce

function decodeBytes(v) {
  const { buffer, byteOffset, byteLength } = Buffer.from(v, 'base64')
  return new Uint8Array(buffer, byteOffset, byteLength)
}
const a = decodeBytes(Buffer.from([1, 2, 3]).toString('base64'))       // value from row/column A
const b = decodeBytes(Buffer.from([9, 9, 9, 9]).toString('base64'))    // value from row/column B

console.log(a.length, a.buffer.byteLength)   // 3 8192
console.log(a.buffer === b.buffer)           // true  — both alias the same pool
console.log(Array.from(new Uint8Array(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.

Suggested fix

Return an owned copy at both sites, e.g.:

return Uint8Array.prototype.slice.call(Buffer.from(value, 'base64'))
// or:
const b = Buffer.from(value, 'base64')
return new Uint8Array(b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength))

Activity

  1. added a commit that references this issue on Jul 22, 2026
    0e286a4
  2. added a commit that references this issue on Aug 9, 2026
    5ad7318
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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