stream: fix decoded fromList chunk boundary check#61884
stream: fix decoded fromList chunk boundary check#61884watson wants to merge 2 commits intonodejs:mainfrom
Conversation
|
Review requested:
|
Correct `fromList()` in decoded string mode to compare `n` against the current chunk length, not the buffer array length. This prevents over-consuming chunks, which can corrupt readable state and crash with `TypeError` when mixing `setEncoding()` and `read(n)`.
8a962b7 to
5ef134f
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #61884 +/- ##
==========================================
- Coverage 91.81% 89.73% -2.08%
==========================================
Files 338 675 +337
Lines 140073 204855 +64782
Branches 22081 39372 +17291
==========================================
+ Hits 128605 183829 +55224
- Misses 11242 13287 +2045
- Partials 226 7739 +7513
🚀 New features to boost your workflow:
|
Commit Queue failed- Loading data for nodejs/node/pull/61884 ✔ Done loading data for nodejs/node/pull/61884 ----------------------------------- PR info ------------------------------------ Title stream: fix decoded fromList chunk boundary check (#61884) Author Thomas Watson <w@tson.dk> (@watson) Branch watson:fix-readable-stream-bug -> nodejs:main Labels stream, author ready, needs-ci Commits 2 - stream: fix decoded fromList chunk boundary check - fix lint Committers 1 - Thomas Watson <w@tson.dk> PR-URL: https://github.com/nodejs/node/pull/61884 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Ilyas Shabi <ilyasshabi94@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/61884 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Ilyas Shabi <ilyasshabi94@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> -------------------------------------------------------------------------------- ℹ This PR was created on Thu, 19 Feb 2026 10:28:10 GMT ✔ Approvals: 9 ✔ - Robert Nagy (@ronag) (TSC): https://github.com/nodejs/node/pull/61884#pullrequestreview-3824865677 ✔ - Ruben Bridgewater (@BridgeAR) (TSC): https://github.com/nodejs/node/pull/61884#pullrequestreview-3824921277 ✔ - Ilyas Shabi (@IlyasShabi): https://github.com/nodejs/node/pull/61884#pullrequestreview-3825273620 ✔ - Gürgün Dayıoğlu (@gurgunday): https://github.com/nodejs/node/pull/61884#pullrequestreview-3825732569 ✔ - Luigi Pinca (@lpinca): https://github.com/nodejs/node/pull/61884#pullrequestreview-3828304463 ✔ - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/61884#pullrequestreview-3828525776 ✔ - Minwoo Jung (@JungMinu): https://github.com/nodejs/node/pull/61884#pullrequestreview-3830500467 ✔ - Colin Ihrig (@cjihrig): https://github.com/nodejs/node/pull/61884#pullrequestreview-3832438069 ✔ - Ethan Arrowood (@Ethan-Arrowood): https://github.com/nodejs/node/pull/61884#pullrequestreview-3832584001 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2026-02-19T11:05:46Z: https://ci.nodejs.org/job/node-test-pull-request/71377/ - Querying data for job/node-test-pull-request/71377/ ✔ Build data downloaded ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ No git cherry-pick in progress ✔ No git am in progress ✔ No git rebase in progress -------------------------------------------------------------------------------- - Bringing origin/main up to date... From https://github.com/nodejs/node * branch main -> FETCH_HEAD ✔ origin/main is now up-to-date - Downloading patch for 61884 From https://github.com/nodejs/node * branch refs/pull/61884/merge -> FETCH_HEAD ✔ Fetched commits as 94df36a12199..2984f1316238 -------------------------------------------------------------------------------- [main 555cb3c22c] stream: fix decoded fromList chunk boundary check Author: Thomas Watson <w@tson.dk> Date: Thu Feb 19 11:25:19 2026 +0100 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-stream2-read-correct-num-bytes-in-utf8.js [main 78184b3a60] fix lint Author: Thomas Watson <w@tson.dk> Date: Thu Feb 19 11:43:24 2026 +0100 1 file changed, 1 insertion(+) ✔ Patches applied There are 2 commits in the PR. Attempting autorebase. (node:458) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated. (Use `node --trace-deprecation ...` to show where the warning was created) Rebasing (2/4) Executing: git node land --amend --yes --------------------------------- New Message ---------------------------------- stream: fix decoded fromList chunk boundary checkhttps://github.com/nodejs/node/actions/runs/22255290326 |
Correct
fromList()in decoded string mode to comparenagainst the current chunk length, not the buffer array length.This prevents over-consuming chunks, which can corrupt readable state and crash with
TypeErrorwhen mixingsetEncoding()andread(n).I reproduced this in all non-EoL release lines.
For reference, here's the script I used to make
read()throw (usually it throws almost instantly, but a few times it can take a little while):And here's the output: