Skip to content

Commit

Permalink
buffer: ignore negative allocation lengths
Browse files Browse the repository at this point in the history
Treat negative length arguments to `Buffer()`/`allocUnsafe()`
as if they were zero so the allocation does not affect the
pool’s offset.

Fixes: #7047

Refs: #7051
Refs: #7221
Refs: #7475
PR-URL: #7562
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Nikolai Vavilov <[email protected]>
  • Loading branch information
addaleax authored and Myles Borins committed Jul 11, 2016
1 parent d5a4a1f commit ee2f08f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ Object.setPrototypeOf(SlowBuffer, Uint8Array);


function allocate(size) {
if (size === 0) {
return createBuffer(size);
if (size <= 0) {
return createBuffer(0);
}
if (size < (Buffer.poolSize >>> 1)) {
if (size > (poolSize - poolOffset))
Expand Down

0 comments on commit ee2f08f

Please sign in to comment.