Repository navigation
stream: stop reusing a detached onread buffer - #67542
Merged
nodejs-github-bot merged 1 commit intoNov 21, 2026
Merged
Conversation
mcollina
force-pushed
the
stream-fix-onread-detached-buffer
branch
from
November 17, 2026 13:54
1497a39 to
4cad0dd
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #67542 +/- ##
==========================================
- Coverage 90.69% 90.69% -0.01%
==========================================
Files 797 801 +4
Lines 278883 280905 +2022
Branches 53630 54254 +624
==========================================
+ Hits 252934 254762 +1828
+ Misses 16314 16271 -43
- Partials 9635 9872 +237
🚀 New features to boost your workflow:
|
mcollina
force-pushed
the
stream-fix-onread-detached-buffer
branch
4 times, most recently
from
November 17, 2026 18:32
a6e20a0 to
88af668
Compare
CustomBufferJSListener keeps only the raw address (uv_buf_t) of the user-supplied onread buffer, without retaining the backing store. If application code transfers (and thereby detaches) that buffer during the onread callback, for example by enqueuing a view into a byte ReadableStream, the backing store is moved away from under the listener and the raw address is left dangling. Reading subsequent peer data into that address then corrupts memory the application owns, and if the backing store is later released, it becomes a use-after-free. Retain the backing store in CustomBufferJSListener so the raw address never dangles, and stop reading when the onread callback detaches the buffer so the stale address is not handed back to libuv. Signed-off-by: Matteo Collina <hello@matteocollina.com>
mcollina
force-pushed
the
stream-fix-onread-detached-buffer
branch
from
November 17, 2026 19:25
88af668 to
174d8f7
Compare
jasnell
approved these changes
Nov 18, 2026
Collaborator
ShogunPanda
approved these changes
Nov 21, 2026
Collaborator
|
Landed in 08eff13 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CustomBufferJSListenerkeeps only the raw address (uv_buf_t) of theuser-supplied
onreadbuffer without retaining the backing store. Ifapplication code transfers (and thereby detaches) that buffer in the
onreadcallback, for example by enqueuing a view into a byte
ReadableStream, thebacking store is moved out from under the listener and the raw address is left
dangling. Reading subsequent peer data into that address then corrupts memory
the application owns, and if the backing store is later released it becomes a
use-after-free.
This retains the backing store in
CustomBufferJSListenerso the raw addressnever dangles, and stops reading when the
onreadcallback detaches thebuffer so the stale address is not handed back to libuv.
A regression test transfers the first received chunk into a byte
ReadableStreamand asserts the retained chunk is not overwritten by a laterpeer write.