mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
buffer: fix unintended unsigned overflow
`offset` is user supplied variable and may be bigger than `ts_obj_length`. There is no need to subtract them and pass along, so just throw when the subtraction result would overflow. PR-URL: https://github.com/nodejs/node/pull/7494 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
1 parent
b3164ae22e
commit
98f51ffeb6
1 file changed
+3
-3
+3
-3
@@ -718,6 +718,9 @@ void StringWrite(const FunctionCallbackInfo<Value>& 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<Value>& 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,
|
||||
|
||||
Reference in new issue
Block a user