Skip to content

Commit 02db891

Browse files
joyeecheungjasnell
authored andcommitted
src: throw ERR_BUFFER_OUT_OF_BOUNDS in node_buffer.cc
PR-URL: #20121 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 0fdf39a commit 02db891

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/node_buffer.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,10 @@ void StringWrite(const FunctionCallbackInfo<Value>& args) {
668668
size_t max_length;
669669

670670
THROW_AND_RETURN_IF_OOB(ParseArrayIndex(args[1], 0, &offset));
671-
if (offset > ts_obj_length)
672-
return env->ThrowRangeError("Offset is out of bounds");
671+
if (offset > ts_obj_length) {
672+
return node::THROW_ERR_BUFFER_OUT_OF_BOUNDS(
673+
env, "\"offset\" is outside of buffer bounds");
674+
}
673675

674676
THROW_AND_RETURN_IF_OOB(ParseArrayIndex(args[2], ts_obj_length - offset,
675677
&max_length));

src/node_errors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace node {
1717
// a `Local<Value>` containing the TypeError with proper code and message
1818

1919
#define ERRORS_WITH_CODE(V) \
20+
V(ERR_BUFFER_OUT_OF_BOUNDS, RangeError) \
2021
V(ERR_INDEX_OUT_OF_RANGE, RangeError) \
2122
V(ERR_INVALID_ARG_TYPE, TypeError) \
2223
V(ERR_MEMORY_ALLOCATION_FAILED, Error) \

0 commit comments

Comments
 (0)