Skip to content

Commit 691915e

Browse files
trivikraduh95
authored andcommitted
stream: validate broadcast writer writev chunks
Validate BroadcastWriter writev() and writevSync() inputs before converting chunks so non-array values throw ERR_INVALID_ARG_TYPE. Fixes: #63299 Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: openai:gpt-5.5 PR-URL: #63300 Fixes: #63299 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
1 parent 253f5f4 commit 691915e

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

lib/internal/streams/iter/broadcast.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ class BroadcastWriter {
463463
}
464464

465465
writev(chunks, options) {
466+
if (!ArrayIsArray(chunks)) {
467+
throw new ERR_INVALID_ARG_TYPE('chunks', 'Array', chunks);
468+
}
466469
// Fast path: no signal, writer open, buffer has space
467470
if (this.#canUseWriteFastPath(options)) {
468471
const converted = convertChunks(chunks);
@@ -523,6 +526,9 @@ class BroadcastWriter {
523526
}
524527

525528
writevSync(chunks) {
529+
if (!ArrayIsArray(chunks)) {
530+
throw new ERR_INVALID_ARG_TYPE('chunks', 'Array', chunks);
531+
}
526532
if (this.#isClosedOrAborted()) return false;
527533
if (!this.#broadcast[kCanWrite]()) return false;
528534
const converted = convertChunks(chunks);

test/parallel/test-stream-iter-validation.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ assert.throws(() => broadcast({ highWaterMark: Number.MAX_SAFE_INTEGER + 1 }),
147147
assert.throws(() => broadcast({ signal: {} }), { code: 'ERR_INVALID_ARG_TYPE' });
148148
assert.throws(() => broadcast({ backpressure: 'bad' }), { code: 'ERR_INVALID_ARG_VALUE' });
149149

150+
// BroadcastWriter.writev requires array
151+
{
152+
const { writer } = broadcast();
153+
assert.throws(() => writer.writev('bad'), { code: 'ERR_INVALID_ARG_TYPE' });
154+
assert.throws(() => writer.writev(42), { code: 'ERR_INVALID_ARG_TYPE' });
155+
assert.throws(() => writer.writevSync('bad'), { code: 'ERR_INVALID_ARG_TYPE' });
156+
assert.throws(() => writer.writevSync(42), { code: 'ERR_INVALID_ARG_TYPE' });
157+
writer.endSync();
158+
}
159+
150160
// Broadcast.from rejects non-iterable input
151161
assert.throws(() => Broadcast.from(42), { code: 'ERR_INVALID_ARG_TYPE' });
152162
assert.throws(() => Broadcast.from('bad'), { code: 'ERR_INVALID_ARG_TYPE' });

0 commit comments

Comments
 (0)