From c404fd1492020a6137c525c90a08cda7e30b4903 Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Fri, 19 Jan 2018 15:40:25 +0100 Subject: [PATCH] Throw error when no buffer is given for `copy()` --- index.js | 3 +++ test/node/test-buffer-alloc.js | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 2584ee7..63479f4 100644 --- a/index.js +++ b/index.js @@ -1445,6 +1445,9 @@ Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) Buffer.prototype.copy = function copy (target, targetStart, start, end) { + if (target === undefined) { + throw new TypeError('argument should be a Buffer') + } if (!start) start = 0 if (!end && end !== 0) end = this.length if (targetStart >= target.length) targetStart = target.length diff --git a/test/node/test-buffer-alloc.js b/test/node/test-buffer-alloc.js index d346521..3f04b3e 100644 --- a/test/node/test-buffer-alloc.js +++ b/test/node/test-buffer-alloc.js @@ -935,11 +935,11 @@ var ps = Buffer.poolSize; Buffer.poolSize = 0; assert(Buffer.allocUnsafe(1).parent instanceof ArrayBuffer); Buffer.poolSize = ps; - +*/ // Test Buffer.copy() segfault assert.throws(() => Buffer.allocUnsafe(10).copy(), /TypeError: argument should be a Buffer/); - +/* var regErrorMsg = new RegExp('The first argument must be one of type string, Buffer, ' + 'ArrayBuffer, Array, or Array-like Object\\.'); -- 2.34.1