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 <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 Myles Borins committed Jul 8, 2016
1 parent 350e8c6 commit 9ef71ab
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

2 comments on commit 9ef71ab

@ChALkeR
Copy link
Member

@ChALkeR ChALkeR commented on 9ef71ab Jul 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also Reviewed-By: Rod Vagg <rod@vagg.org> in #7562 (comment).

@MylesBorins
Copy link
Contributor

@MylesBorins MylesBorins commented on 9ef71ab Jul 8, 2016 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.