Skip to content

Commit 57c3035

Browse files
watsonmarco-ippolito
authored andcommitted
stream: fix decoded fromList chunk boundary check
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)`. PR-URL: #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>
1 parent ecfa766 commit 57c3035

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎lib/internal/streams/readable.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,7 @@ function fromList(n, state) {
16331633
n-=str.length;
16341634
buf[idx++]=null;
16351635
}else{
1636-
if(n===buf.length){
1636+
if(n===str.length){
16371637
ret+=str;
16381638
buf[idx++]=null;
16391639
}else{
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
require('../common');
4+
constassert=require('assert');
5+
const{ Readable }=require('stream');
6+
7+
constreadable=newReadable({read(){}});
8+
readable.setEncoding('utf8');
9+
10+
readable.push('abc');
11+
readable.push('defgh');
12+
readable.push(null);
13+
14+
assert.strictEqual(readable.read(5),'abcde');
15+
assert.strictEqual(readable.read(3),'fgh');
16+
assert.strictEqual(readable.read(1),null);

0 commit comments

Comments
 (0)