diff --git a/src/node_buffer.cc b/src/node_buffer.cc index fa45d28b8f..eda51cac20 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -718,6 +718,9 @@ void StringWrite(const FunctionCallbackInfo& args) { size_t max_length; CHECK_NOT_OOB(ParseArrayIndex(args[1], 0, &offset)); + if (offset >= ts_obj_length) + return env->ThrowRangeError("Offset is out of bounds"); + CHECK_NOT_OOB(ParseArrayIndex(args[2], ts_obj_length - offset, &max_length)); max_length = MIN(ts_obj_length - offset, max_length); @@ -725,9 +728,6 @@ void StringWrite(const FunctionCallbackInfo& args) { if (max_length == 0) return args.GetReturnValue().Set(0); - if (offset >= ts_obj_length) - return env->ThrowRangeError("Offset is out of bounds"); - uint32_t written = StringBytes::Write(env->isolate(), ts_obj_data + offset, max_length,