Skip to content

Commit d44540f

Browse files
trevnorrisMyles Borins
authored and
Myles Borins
committed
buffer: standardize array index check
ParseArrayIndex() was requesting a Uint32Value(), but assigning it to an in32_t. This caused slight differences in error message reported in edge cases of argument parsing. Fixed by getting the IntegerValue() before checking if the value is < 0. Added test of API that was affected. PR-URL: #6084 Reviewed-By: James M Snell <[email protected]>
1 parent 440d117 commit d44540f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/node_internals.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ inline MUST_USE_RESULT bool ParseArrayIndex(v8::Local<v8::Value> arg,
167167
return true;
168168
}
169169

170-
int32_t tmp_i = arg->Uint32Value();
170+
int64_t tmp_i = arg->IntegerValue();
171171

172172
if (tmp_i < 0)
173173
return false;

test/parallel/test-buffer-alloc.js

+6
Original file line numberDiff line numberDiff line change
@@ -1429,3 +1429,9 @@ assert.equal(Buffer.prototype.parent, undefined);
14291429
assert.equal(Buffer.prototype.offset, undefined);
14301430
assert.equal(SlowBuffer.prototype.parent, undefined);
14311431
assert.equal(SlowBuffer.prototype.offset, undefined);
1432+
1433+
1434+
// Test that ParseArrayIndex handles full uint32
1435+
assert.throws(function() {
1436+
Buffer.from(new ArrayBuffer(0), -1 >>> 0);
1437+
}, /RangeError: 'offset' is out of bounds/);

0 commit comments

Comments
 (0)