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: nodejs#7047

Refs: nodejs#7051
Refs: nodejs#7221
Refs: nodejs#7475
PR-URL: nodejs#7562
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Nikolai Vavilov <vvnicholas@gmail.com>
  • Loading branch information
addaleax authored and ChALkeR committed Jul 8, 2016
1 parent b69bcaf commit 18b5ef9
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 18b5ef9

Please sign in to comment.