mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
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: https://github.com/nodejs/node/issues/63299 Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: openai:gpt-5.5 PR-URL: https://github.com/nodejs/node/pull/63300 Backport-PR-URL: https://github.com/nodejs/node/pull/64675 Fixes: https://github.com/nodejs/node/issues/63299 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
This commit is contained in:
1 parent
944470b08a
commit
f63143fd83
2 files changed
+16
No files matched your search
@@ -463,6 +463,9 @@ class BroadcastWriter {
|
||||
}
|
||||
|
||||
writev(chunks, options) {
|
||||
if (!ArrayIsArray(chunks)) {
|
||||
throw new ERR_INVALID_ARG_TYPE('chunks', 'Array', chunks);
|
||||
}
|
||||
// Fast path: no signal, writer open, buffer has space
|
||||
if (this.#canUseWriteFastPath(options)) {
|
||||
const converted = convertChunks(chunks);
|
||||
@@ -523,6 +526,9 @@ class BroadcastWriter {
|
||||
}
|
||||
|
||||
writevSync(chunks) {
|
||||
if (!ArrayIsArray(chunks)) {
|
||||
throw new ERR_INVALID_ARG_TYPE('chunks', 'Array', chunks);
|
||||
}
|
||||
if (this.#isClosedOrAborted()) return false;
|
||||
if (!this.#broadcast[kCanWrite]()) return false;
|
||||
const converted = convertChunks(chunks);
|
||||
|
||||
@@ -147,6 +147,16 @@ assert.throws(() => broadcast({ highWaterMark: Number.MAX_SAFE_INTEGER + 1 }),
|
||||
assert.throws(() => broadcast({ signal: {} }), { code: 'ERR_INVALID_ARG_TYPE' });
|
||||
assert.throws(() => broadcast({ backpressure: 'bad' }), { code: 'ERR_INVALID_ARG_VALUE' });
|
||||
|
||||
// BroadcastWriter.writev requires array
|
||||
{
|
||||
const { writer } = broadcast();
|
||||
assert.throws(() => writer.writev('bad'), { code: 'ERR_INVALID_ARG_TYPE' });
|
||||
assert.throws(() => writer.writev(42), { code: 'ERR_INVALID_ARG_TYPE' });
|
||||
assert.throws(() => writer.writevSync('bad'), { code: 'ERR_INVALID_ARG_TYPE' });
|
||||
assert.throws(() => writer.writevSync(42), { code: 'ERR_INVALID_ARG_TYPE' });
|
||||
writer.endSync();
|
||||
}
|
||||
|
||||
// Broadcast.from rejects non-iterable input
|
||||
assert.throws(() => Broadcast.from(42), { code: 'ERR_INVALID_ARG_TYPE' });
|
||||
assert.throws(() => Broadcast.from('bad'), { code: 'ERR_INVALID_ARG_TYPE' });
|
||||
|
||||
Reference in new issue
Block a user