Skip to content

Commit 66906c4

Browse files
committed
buffer: fix copy() segfault with zero arguments
Buffer#copy() immediately does a ToObject() on the first argument before it checks if it's even an Object. This causes Object::HasIndexedPropertiesInExternalArrayData() to be run on nothing, triggering the segfault. Instead run HasInstance() on the args Value. Which will check if it's actually an Object, before checking if it contains data. Fixes: #1519
1 parent 2f6986e commit 66906c4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/node_buffer.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,11 @@ void Base64Slice(const FunctionCallbackInfo<Value>& args) {
303303
void Copy(const FunctionCallbackInfo<Value> &args) {
304304
Environment* env = Environment::GetCurrent(args);
305305

306-
Local<Object> target = args[0]->ToObject(env->isolate());
307-
308-
if (!HasInstance(target))
306+
if (!HasInstance(args[0]))
309307
return env->ThrowTypeError("first arg should be a Buffer");
310308

309+
Local<Object> target = args[0]->ToObject(env->isolate());
310+
311311
ARGS_THIS(args.This())
312312
size_t target_length = target->GetIndexedPropertiesExternalArrayDataLength();
313313
char* target_data = static_cast<char*>(

0 commit comments

Comments
 (0)