diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-04-02 00:01:29 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-04-15 17:21:34 +0200 |
commit | 693401d0ddd752e5fa47b882e56e252c42c94c0e (patch) | |
tree | fadabceddc0df7bd8d982bcd6c00cc11f3565e5d /test/parallel/test-buffer-fill.js | |
parent | 2fed83dee884c3bddafa67bb53abf507db1a8ba3 (diff) | |
download | android-node-v8-693401d0ddd752e5fa47b882e56e252c42c94c0e.tar.gz android-node-v8-693401d0ddd752e5fa47b882e56e252c42c94c0e.tar.bz2 android-node-v8-693401d0ddd752e5fa47b882e56e252c42c94c0e.zip |
buffer: use stricter range checks
This validates the input to make sure the arguments do not overflow.
Before, if the input would overflow, it would cause the write to be
performt in the wrong spot / result in unexpected behavior.
Instead, just use a strict number validation.
PR-URL: https://github.com/nodejs/node/pull/27045
Fixes: https://github.com/nodejs/node/issues/27043
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test/parallel/test-buffer-fill.js')
-rw-r--r-- | test/parallel/test-buffer-fill.js | 23 |
1 files changed, 3 insertions, 20 deletions
diff --git a/test/parallel/test-buffer-fill.js b/test/parallel/test-buffer-fill.js index 61ff6bbb50..3dd11bce26 100644 --- a/test/parallel/test-buffer-fill.js +++ b/test/parallel/test-buffer-fill.js @@ -333,34 +333,17 @@ assert.strictEqual( // Make sure "end" is properly checked, even if it's magically mangled using // Symbol.toPrimitive. { - let elseWasLast = false; - const expectedErrorMessage = - 'The value of "end" is out of range. It must be >= 0 and <= 1. Received -1'; - common.expectsError(() => { - let ctr = 0; const end = { [Symbol.toPrimitive]() { - // We use this condition to get around the check in lib/buffer.js - if (ctr === 0) { - elseWasLast = false; - ctr++; - return 1; - } - elseWasLast = true; - // Once buffer.js calls the C++ implementation of fill, return -1 - return -1; + return 1; } }; Buffer.alloc(1).fill(Buffer.alloc(1), 0, end); }, { - code: 'ERR_OUT_OF_RANGE', - type: RangeError, - message: expectedErrorMessage + code: 'ERR_INVALID_ARG_TYPE', + message: 'The "end" argument must be of type number. Received type object' }); - // Make sure -1 is making it to Buffer::Fill(). - assert.ok(elseWasLast, - 'internal API changed, -1 no longer in correct location'); } // Testing process.binding. Make sure "end" is properly checked for -1 wrap |