Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e146591

Browse filesBrowse files
watsonaduh95
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 5a9874a commit e146591
Copy full SHA for e146591

2 files changed

+17-1Lines changed: 17 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/streams/readable.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/readable.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ function fromList(n, state) {
16641664
n -= str.length;
16651665
buf[idx++] = null;
16661666
} else {
1667-
if (n === buf.length) {
1667+
if (n === str.length) {
16681668
ret += str;
16691669
buf[idx++] = null;
16701670
} else {
Collapse file
+16Lines 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+
const assert = require('assert');
5+
const { Readable } = require('stream');
6+
7+
const readable = new Readable({ 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.