Skip to content

Commit f17b3e2

Browse files
addaleaxChALkeR
authored andcommitted
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: nodejs#7047 Refs: nodejs#7051 PR-URL: nodejs#7221 Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent e2ccf62 commit f17b3e2

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)