Skip to content

Commit 200429e

Browse files
addaleaxMyles Borins
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: #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‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ Object.setPrototypeOf(SlowBuffer, Uint8Array);
7979

8080

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

0 commit comments

Comments
(0)