Skip to content

fix(client): copy Bytes values out of Node's shared Buffer pool on deserialization - #29701

Merged
aqrln merged 1 commit into
prisma:mainfrom
thribhuvan003:fix/bytes-shared-buffer-pool
Jul 22, 2026
Merged

fix(client): copy Bytes values out of Node's shared Buffer pool on deserialization#29701
aqrln merged 1 commit into
prisma:mainfrom
thribhuvan003:fix/bytes-shared-buffer-pool

Conversation

@thribhuvan003

Copy link
Copy Markdown
Contributor

Fixes #29694

Bytes values come back as a Uint8Array that is a view into Node's shared 8 KB Buffer pool, so field.buffer is the whole pool — including bytes from other decoded values — and field.buffer.byteLength is 8192 instead of the value's real length. This changes both decode sites (structured results and $queryRaw) to copy into a standalone buffer instead of keeping the pool view. Added a test in each package asserting the returned array owns its buffer.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This change modifies how Bytes values are deserialized in two locations: packages/client-engine-runtime/src/json-protocol.ts and packages/client/src/runtime/utils/deserializeRawResults.ts. Both now construct a Uint8Array by copying from a base64-decoded Buffer, rather than creating a view over the Buffer's underlying memory using extracted buffer, byteOffset, and byteLength. Corresponding tests were added in both packages to assert the returned Uint8Array is backed by a standalone buffer, checking byteOffset equals zero and that the buffer's byte length matches the value's byte length.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR addresses #29694 by fixing both deserialization paths and adding coverage for standalone buffers.
Out of Scope Changes check ✅ Passed The changes stay focused on the Bytes deserialization fix and related tests, with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately summarizes the main change: copying Bytes values off Node's shared Buffer pool during deserialization.
Description check ✅ Passed The description matches the implemented fix and test coverage for both deserialization paths.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@tensordreams
tensordreams changed the base branch from main to v7 July 21, 2026 12:04
@tensordreams
tensordreams changed the base branch from v7 to main July 21, 2026 15:09
@codspeed-hq

codspeed-hq Bot commented Jul 21, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 97.28%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 16 untouched benchmarks
⏩ 30 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
compile blog post page (uncached baseline) 3.3 ms 122.8 ms -97.28%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing thribhuvan003:fix/bytes-shared-buffer-pool (384f19a) with main (aef8cb5)

Open in CodSpeed

Footnotes

  1. 30 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@aqrln aqrln left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. This is unfortunate that we have to do this but safety and correctness come first.

If this causes measurable performance issues for large buffers, we could change this to only clone the buffers up to 4 KB which are actually pooled.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 22, 2026
@aqrln
aqrln merged commit 0e286a4 into prisma:main Jul 22, 2026
251 of 254 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants