mirror of
https://github.com/nodejs/node.git
synced 2026-12-05 07:18:51 -05:00
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>
This commit is contained in:
1 parent
341b3d01c8
commit
72fb796bed
2 files changed
+13
-3
No files matched your search
+3
-3
@@ -804,14 +804,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;
|
||||
|
||||
Reference in new issue
Block a user