Skip to content

Commit 43e2c2e

Browse files
DavenportEmmacodebytere
authored andcommitted
src: change Fill() to use ParseArrayIndex()
Changed Fill() to use ParseArrayIndex() when getting start and end of buffers instead of Uint32Value, supporting buffers of greater than 2**32 Fixes: #31514 Co-Authored-By: Rich Trott <rtrott@gmail.com> PR-URL: #31591 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent f6392e9 commit 43e2c2e

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/node_buffer.cc

+5-4
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,11 @@ void Fill(const FunctionCallbackInfo<Value>& args) {
568568
THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]);
569569
SPREAD_BUFFER_ARG(args[0], ts_obj);
570570

571-
uint32_t start;
572-
if (!args[2]->Uint32Value(ctx).To(&start)) return;
573-
uint32_t end;
574-
if (!args[3]->Uint32Value(ctx).To(&end)) return;
571+
size_t start;
572+
THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[2], 0, &start));
573+
size_t end;
574+
THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[3], 0, &end));
575+
575576
size_t fill_length = end - start;
576577
Local<String> str_obj;
577578
size_t str_length;

test/parallel/test-buffer-fill.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,12 @@ Buffer.alloc(8, '');
325325
assert.strictEqual(buf.toString(), 'էէէէէ');
326326
}
327327

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+
);
332334

333335
// Make sure "end" is properly checked, even if it's magically mangled using
334336
// Symbol.toPrimitive.
@@ -347,10 +349,12 @@ assert.strictEqual(
347349
});
348350
}
349351

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+
);
354358

355359
// Test that bypassing 'length' won't cause an abort.
356360
assert.throws(() => {

0 commit comments

Comments
 (0)