From 02db891bcc61907e0158ac328176d79439c8470b Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 16 Apr 2018 23:52:54 +0800 Subject: [PATCH] src: throw ERR_BUFFER_OUT_OF_BOUNDS in node_buffer.cc PR-URL: https://github.com/nodejs/node/pull/20121 Reviewed-By: Daniel Bevenius Reviewed-By: Anna Henningsen Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Jeremiah Senkpiel --- src/node_buffer.cc | 6 ++++-- src/node_errors.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 997e4fd2299cdb..b00886f5e680ba 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -668,8 +668,10 @@ void StringWrite(const FunctionCallbackInfo& args) { size_t max_length; THROW_AND_RETURN_IF_OOB(ParseArrayIndex(args[1], 0, &offset)); - if (offset > ts_obj_length) - return env->ThrowRangeError("Offset is out of bounds"); + if (offset > ts_obj_length) { + return node::THROW_ERR_BUFFER_OUT_OF_BOUNDS( + env, "\"offset\" is outside of buffer bounds"); + } THROW_AND_RETURN_IF_OOB(ParseArrayIndex(args[2], ts_obj_length - offset, &max_length)); diff --git a/src/node_errors.h b/src/node_errors.h index 1ebedc2fcb5a9b..fadbdbe37408b1 100644 --- a/src/node_errors.h +++ b/src/node_errors.h @@ -17,6 +17,7 @@ namespace node { // a `Local` containing the TypeError with proper code and message #define ERRORS_WITH_CODE(V) \ + V(ERR_BUFFER_OUT_OF_BOUNDS, RangeError) \ V(ERR_INDEX_OUT_OF_RANGE, RangeError) \ V(ERR_INVALID_ARG_TYPE, TypeError) \ V(ERR_MEMORY_ALLOCATION_FAILED, Error) \