Skip to content

Commit 200429e

Browse files
addaleaxMyles Borins
authored and
Myles Borins
committedJul 14, 2016
buffer: ignore negative allocation lengths
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]>
1 parent e544b1c commit 200429e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed
 

‎lib/buffer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ Object.setPrototypeOf(SlowBuffer, Uint8Array);
7979

8080

8181
function allocate(size) {
82-
if (size === 0) {
83-
return createBuffer(size);
82+
if (size <= 0) {
83+
return createBuffer(0);
8484
}
8585
if (size < (Buffer.poolSize >>> 1)) {
8686
if (size > (poolSize - poolOffset))

0 commit comments

Comments
 (0)
Please sign in to comment.