Skip to content

Commit 9d94cc5

Browse files
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: nodejs#6084 Reviewed-By: James M Snell <[email protected]>
1 parent 9454548 commit 9d94cc5

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/node_internals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ inline MUST_USE_RESULT bool ParseArrayIndex(v8::Local<v8::Value> arg,
169169
return true;
170170
}
171171

172-
int32_t tmp_i = arg->Uint32Value();
172+
int64_t tmp_i = arg->IntegerValue();
173173

174174
if (tmp_i < 0)
175175
return false;

test/parallel/test-buffer-alloc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,3 +1440,9 @@ assert.equal(Buffer.prototype.parent, undefined);
14401440
assert.equal(Buffer.prototype.offset, undefined);
14411441
assert.equal(SlowBuffer.prototype.parent, undefined);
14421442
assert.equal(SlowBuffer.prototype.offset, undefined);
1443+
1444+
1445+
// Test that ParseArrayIndex handles full uint32
1446+
assert.throws(function() {
1447+
Buffer.from(new ArrayBuffer(0), -1 >>> 0);
1448+
}, /RangeError: 'offset' is out of bounds/);

0 commit comments

Comments
 (0)