diff --git a/lib/buffer.js b/lib/buffer.js index 3be54669619567..a5f7ec5ffbb7b1 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -218,7 +218,7 @@ function fromArrayBuffer(obj, byteOffset, length) { const maxLength = obj.byteLength - byteOffset; - if (maxLength <= 0) + if (maxLength < 0) throw new RangeError("'offset' is out of bounds"); if (length === undefined) { diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js index c06c1107039cb2..b771054bdd0656 100644 --- a/test/parallel/test-buffer-alloc.js +++ b/test/parallel/test-buffer-alloc.js @@ -1458,3 +1458,8 @@ const ubuf = Buffer.allocUnsafeSlow(10); assert(ubuf); assert(ubuf.buffer); assert.equal(ubuf.buffer.byteLength, 10); + +// Regression test +assert.doesNotThrow(() => { + Buffer.from(new ArrayBuffer()); +});