Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
buffer: fix creating from zero-length ArrayBuffer
Fixes regression where creating a new Buffer from an
empty ArrayBuffer would fail.

Ref: 85ab4a5
  • Loading branch information
RReverser committed Jun 6, 2016
commit 6ff1a51c8dc005012c27d6eb3507c19f48e14e2d
2 changes: 1 addition & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,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) {
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-buffer-alloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});