From ebcba82a93317688ac51bf50015276c2aa344610 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Tue, 2 Apr 2019 00:01:29 +0200 Subject: [PATCH 1/2] buffer: use stricter range checks This adds support to use offset and length arguments above uint32 and it 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. Fixes: https://github.com/nodejs/node/issues/27043 --- doc/api/errors.md | 12 ++-- lib/buffer.js | 61 +++++++++++---------- lib/internal/errors.js | 1 - test/parallel/test-buffer-alloc.js | 11 ++-- test/parallel/test-buffer-compare-offset.js | 37 +++++++++---- test/parallel/test-buffer-fill.js | 23 +------- 6 files changed, 75 insertions(+), 70 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 2ad0bead8ec0bb..e93797d9d3ba62 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1574,12 +1574,6 @@ OpenSSL crypto support. An attempt was made to use features that require [ICU][], but Node.js was not compiled with ICU support. - -### ERR_NO_LONGER_SUPPORTED - -A Node.js API was called in an unsupported manner, such as -`Buffer.write(string, encoding, offset[, length])`. - ### ERR_OUT_OF_RANGE @@ -2095,6 +2089,12 @@ removed: v10.0.0 Used by the `N-API` when `Constructor.prototype` is not an object. + +### ERR_NO_LONGER_SUPPORTED + +A Node.js API was called in an unsupported manner, such as +`Buffer.write(string, encoding, offset[, length])`. + ### ERR_OUTOFMEMORY