Skip to content

Commit eec6f0a

Browse files
committed
stream: validate all elements in isUint8ArrayBatch
`isUint8ArrayBatch` only checked the first array element, so a mixed array like `[Uint8Array, "hello"]` would pass the fast-path check and flow through un-normalized. Use `ArrayPrototypeEvery` to validate all elements. Also replaced inline first-element-only checks in `processTransformResultSync` and `processTransformResultAsync` with the corrected `isUint8ArrayBatch` function.
1 parent 4e30386 commit eec6f0a

2 files changed

Lines changed: 3 additions & 9 deletions

File tree

lib/internal/streams/iter/from.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ function* normalizeSyncValue(value) {
253253
function isUint8ArrayBatch(value) {
254254
if (!ArrayIsArray(value)) return false;
255255
if (value.length === 0) return true;
256-
// Check first element - if it's a Uint8Array, assume the rest are too
257-
return isUint8Array(value[0]);
256+
return ArrayPrototypeEvery(value, isUint8Array);
258257
}
259258

260259
/**

lib/internal/streams/iter/pull.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// through transforms to consumer.
88

99
const {
10-
ArrayIsArray,
1110
ArrayPrototypePush,
1211
ArrayPrototypeSlice,
1312
String,
@@ -178,9 +177,7 @@ function* processTransformResultSync(result) {
178177
if (result === null) {
179178
return;
180179
}
181-
if (ArrayIsArray(result) && result.length > 0 &&
182-
isUint8Array(result[0])) {
183-
// Fast path: Uint8Array[]
180+
if (isUint8ArrayBatch(result)) {
184181
if (result.length > 0) {
185182
yield result;
186183
}
@@ -216,9 +213,7 @@ async function* processTransformResultAsync(result) {
216213
if (result === null) {
217214
return;
218215
}
219-
if (ArrayIsArray(result) &&
220-
(result.length === 0 || isUint8Array(result[0]))) {
221-
// Fast path: Uint8Array[]
216+
if (isUint8ArrayBatch(result)) {
222217
if (result.length > 0) {
223218
yield result;
224219
}

0 commit comments

Comments
 (0)