From 693401d0ddd752e5fa47b882e56e252c42c94c0e Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Tue, 2 Apr 2019 00:01:29 +0200 Subject: [PATCH] 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 Reviewed-By: Rich Trott --- doc/api/errors.md | 12 ++-- lib/buffer.js | 73 +++++++++------------ lib/internal/errors.js | 1 - test/parallel/test-buffer-alloc.js | 30 +++++---- test/parallel/test-buffer-compare-offset.js | 42 ++++++++---- test/parallel/test-buffer-fill.js | 23 +------ test/parallel/test-buffer-write.js | 19 +++--- 7 files changed, 98 insertions(+), 102 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 547d1ff8d23609..e984487820220c 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1564,12 +1564,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 @@ -2096,6 +2090,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