diff options
author | Matt Loring <mattloring@google.com> | 2016-03-08 11:15:01 -0800 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-03-21 21:51:33 -0700 |
commit | d3c0d1bb8bcc039637a259e5885909aba8fa1195 (patch) | |
tree | 1b43db5970537a2276ec27c28fd3ae8d7b96efb4 /src | |
parent | cde81b6b9f3d39629ccacae5f9e82ba2527c4f29 (diff) | |
download | android-node-v8-d3c0d1bb8bcc039637a259e5885909aba8fa1195.tar.gz android-node-v8-d3c0d1bb8bcc039637a259e5885909aba8fa1195.tar.bz2 android-node-v8-d3c0d1bb8bcc039637a259e5885909aba8fa1195.zip |
buffer: throw range error before truncating write
The check to determine whether `noAssert` was set to true and thus
whether RangeErrors should be thrown was happening after the write was
truncated to the available size of the buffer. These checks now occur in
the correct order.
Fixes: https://github.com/nodejs/node/issues/5587
PR-URL: https://github.com/nodejs/node/pull/5605
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/node_buffer.cc | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 4d23c4c283..a4a7ec159d 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -814,14 +814,14 @@ void WriteFloatGeneric(const FunctionCallbackInfo<Value>& args) { size_t offset = args[2]->IntegerValue(env->context()).FromMaybe(0); size_t memcpy_num = sizeof(T); - if (offset + sizeof(T) > ts_obj_length) - memcpy_num = ts_obj_length - offset; if (should_assert) { CHECK_NOT_OOB(offset + memcpy_num >= memcpy_num); CHECK_NOT_OOB(offset + memcpy_num <= ts_obj_length); } - CHECK_LE(offset + memcpy_num, ts_obj_length); + + if (offset + memcpy_num > ts_obj_length) + memcpy_num = ts_obj_length - offset; union NoAlias { T val; |