GeezerVison is showing github.com — stream: validate broadcast writer writev chunks · nodejs/node@f63143f
File tree
Expand file treeCollapse file tree
Open diff view settings
lib/internal/streams/iter
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/streams/iter/broadcast.js +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -463,6 +463,9 @@ class BroadcastWriter { |
463 | 463 | } |
464 | 464 |
|
465 | 465 | writev(chunks, options) { |
| 466 | + if (!ArrayIsArray(chunks)) { |
| 467 | + throw new ERR_INVALID_ARG_TYPE('chunks', 'Array', chunks); |
| 468 | + } |
466 | 469 | // Fast path: no signal, writer open, buffer has space |
467 | 470 | if (this.#canUseWriteFastPath(options)) { |
468 | 471 | const converted = convertChunks(chunks); |
@@ -523,6 +526,9 @@ class BroadcastWriter { |
523 | 526 | } |
524 | 527 |
|
525 | 528 | writevSync(chunks) { |
| 529 | + if (!ArrayIsArray(chunks)) { |
| 530 | + throw new ERR_INVALID_ARG_TYPE('chunks', 'Array', chunks); |
| 531 | + } |
526 | 532 | if (this.#isClosedOrAborted()) return false; |
527 | 533 | if (!this.#broadcast[kCanWrite]()) return false; |
528 | 534 | const converted = convertChunks(chunks); |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-stream-iter-validation.js +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -147,6 +147,16 @@ assert.throws(() => broadcast({ highWaterMark: Number.MAX_SAFE_INTEGER + 1 }), |
147 | 147 | assert.throws(() => broadcast({ signal: {} }), { code: 'ERR_INVALID_ARG_TYPE' }); |
148 | 148 | assert.throws(() => broadcast({ backpressure: 'bad' }), { code: 'ERR_INVALID_ARG_VALUE' }); |
149 | 149 |
|
| 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 | + |
150 | 160 | // Broadcast.from rejects non-iterable input |
151 | 161 | assert.throws(() => Broadcast.from(42), { code: 'ERR_INVALID_ARG_TYPE' }); |
152 | 162 | assert.throws(() => Broadcast.from('bad'), { code: 'ERR_INVALID_ARG_TYPE' }); |
|