Skip to content

Commit 4a3300e

Browse files
RReverserevanlucas
authored andcommitted
buffer: fix creating from zero-length ArrayBuffer
Fixes regression where creating a new Buffer from an empty ArrayBuffer would fail. Ref: 85ab4a5 PR-URL: #7176 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: Ron Korving <[email protected]>
1 parent 2a023bf commit 4a3300e

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

‎lib/buffer.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ function fromArrayBuffer(obj, byteOffset, length){
218218

219219
constmaxLength=obj.byteLength-byteOffset;
220220

221-
if(maxLength<=0)
221+
if(maxLength<0)
222222
thrownewRangeError("'offset' is out of bounds");
223223

224224
if(length===undefined){

‎test/parallel/test-buffer-alloc.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,3 +1458,8 @@ const ubuf = Buffer.allocUnsafeSlow(10);
14581458
assert(ubuf);
14591459
assert(ubuf.buffer);
14601460
assert.equal(ubuf.buffer.byteLength,10);
1461+
1462+
// Regression test
1463+
assert.doesNotThrow(()=>{
1464+
Buffer.from(newArrayBuffer());
1465+
});

0 commit comments

Comments
(0)