buffer: ignore negative allocation lengths
Checklist
-
tests and code linting passes -
a test and/or benchmark is included -
the commit message follows commit guidelines
Affected core subsystem(s)
buffer
Description of change
Treat negative length arguments to Buffer()
/allocUnsafe()
as if they were zero so the allocation does not affect the pool’s offset.
Ref: https://github.com/nodejs/node/issues/7047
I decided to not throw an error here because there’s at least one existing test expecting Buffer(-1)
to not throw, but I’d like to make a semver-major follow-up PR for adding a < 0
check to assertSize
. (That would implement this suggestion by @thefourtheye, I think.)
/cc @nodejs/buffer