Skip to content

Commit

Permalink
buffer: standardize array index check
Browse files Browse the repository at this point in the history
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 <jasnell@gmail.com>
  • Loading branch information
trevnorris authored and Myles Borins committed Apr 20, 2016
1 parent 440d117 commit d44540f
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/node_internals.h
Original file line number Diff line number Diff line change
@@ -167,7 +167,7 @@ inline MUST_USE_RESULT bool ParseArrayIndex(v8::Local<v8::Value> arg,
return true;
}

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

if (tmp_i < 0)
return false;
6 changes: 6 additions & 0 deletions test/parallel/test-buffer-alloc.js
Original file line number Diff line number Diff line change
@@ -1429,3 +1429,9 @@ assert.equal(Buffer.prototype.parent, undefined);
assert.equal(Buffer.prototype.offset, undefined);
assert.equal(SlowBuffer.prototype.parent, undefined);
assert.equal(SlowBuffer.prototype.offset, undefined);


// Test that ParseArrayIndex handles full uint32
assert.throws(function() {
Buffer.from(new ArrayBuffer(0), -1 >>> 0);
}, /RangeError: 'offset' is out of bounds/);

0 comments on commit d44540f

Please sign in to comment.