Skip to content
Closed
Prev Previous commit
Next Next commit
src: throw ERR_BUFFER_OUT_OF_BOUNDS in node_buffer.cc
  • Loading branch information
joyeecheung committed Apr 18, 2018
commit 185c60d05eb6c44b6829ce4ea30fdb9e13afdad6
6 changes: 4 additions & 2 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,10 @@ void StringWrite(const FunctionCallbackInfo<Value>& 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));
Expand Down
1 change: 1 addition & 0 deletions src/node_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace node {
// a `Local<Value>` 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) \
Expand Down