From d44540f5af43fe13f5bfb3597de24197aaf29fce Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Wed, 6 Apr 2016 16:04:40 -0600 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/6084 Reviewed-By: James M Snell --- src/node_internals.h | 2 +- test/parallel/test-buffer-alloc.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/node_internals.h b/src/node_internals.h index e17f6ca2e47f37..60530e8a5f81e9 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -167,7 +167,7 @@ inline MUST_USE_RESULT bool ParseArrayIndex(v8::Local arg, return true; } - int32_t tmp_i = arg->Uint32Value(); + int64_t tmp_i = arg->IntegerValue(); if (tmp_i < 0) return false; diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js index 8b9dae91647231..589ec74e138754 100644 --- a/test/parallel/test-buffer-alloc.js +++ b/test/parallel/test-buffer-alloc.js @@ -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/);