GeezerVison is showing github.com — src: change Fill() to use ParseArrayIndex() · e7dal/node@d4660ab
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/node_buffer.cc +5-4Lines changed: 5 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -590,10 +590,11 @@ void Fill(const FunctionCallbackInfo<Value>& args) { | 590 | 590 | THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); | 591 | 591 | SPREAD_BUFFER_ARG(args[0], ts_obj); | 592 | 592 |
| 593 | | - uint32_t start; | 594 | | - if (!args[2]->Uint32Value(ctx).To(&start)) return; | 595 | | - uint32_t end; | 596 | | - if (!args[3]->Uint32Value(ctx).To(&end)) return; | | 593 | + size_t start; | | 594 | + THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[2], 0, &start)); | | 595 | + size_t end; | | 596 | + THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[3], 0, &end)); | | 597 | + | 597 | 598 | size_t fill_length = end - start; | 598 | 599 | Local<String> str_obj; | 599 | 600 | size_t str_length; | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-buffer-fill.js +12-8Lines changed: 12 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -325,10 +325,12 @@ Buffer.alloc(8, ''); | 325 | 325 | assert.strictEqual(buf.toString(), 'էէէէէ'); | 326 | 326 | } | 327 | 327 |
| 328 | | -// Testing process.binding. Make sure "start" is properly checked for -1 wrap | 329 | | -// around. | 330 | | -assert.strictEqual( | 331 | | - internalBinding('buffer').fill(Buffer.alloc(1), 1, -1, 0, 1), -2); | | 328 | +// Testing process.binding. Make sure "start" is properly checked for range | | 329 | +// errors. | | 330 | +assert.throws( | | 331 | + () => { internalBinding('buffer').fill(Buffer.alloc(1), 1, -1, 0, 1); }, | | 332 | + { code: 'ERR_OUT_OF_RANGE' } | | 333 | +); | 332 | 334 |
| 333 | 335 | // Make sure "end" is properly checked, even if it's magically mangled using | 334 | 336 | // Symbol.toPrimitive. | @@ -347,10 +349,12 @@ assert.strictEqual( | 347 | 349 | }); | 348 | 350 | } | 349 | 351 |
| 350 | | -// Testing process.binding. Make sure "end" is properly checked for -1 wrap | 351 | | -// around. | 352 | | -assert.strictEqual( | 353 | | - internalBinding('buffer').fill(Buffer.alloc(1), 1, 1, -2, 1), -2); | | 352 | +// Testing process.binding. Make sure "end" is properly checked for range | | 353 | +// errors. | | 354 | +assert.throws( | | 355 | + () => { internalBinding('buffer').fill(Buffer.alloc(1), 1, 1, -2, 1); }, | | 356 | + { code: 'ERR_OUT_OF_RANGE' } | | 357 | +); | 354 | 358 |
| 355 | 359 | // Test that bypassing 'length' won't cause an abort. | 356 | 360 | assert.throws(() => { | |
|