summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2016-05-29 20:03:32 +0200
committerAnna Henningsen <anna@addaleax.net>2016-05-31 18:52:42 +0200
commitef9a8fa35b1755d53da0eba5b4a768f14f084eff (patch)
tree6afcc2a367943b6e14b98de1f7b9df0310cd3cef /lib
parent0cc903544df7759b50056487b528426f1fce08d8 (diff)
downloadandroid-node-v8-ef9a8fa35b1755d53da0eba5b4a768f14f084eff.tar.gz
android-node-v8-ef9a8fa35b1755d53da0eba5b4a768f14f084eff.tar.bz2
android-node-v8-ef9a8fa35b1755d53da0eba5b4a768f14f084eff.zip
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: https://github.com/nodejs/node/issues/7047 PR-URL: https://github.com/nodejs/node/pull/7051 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/buffer.js4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/buffer.js b/lib/buffer.js
index a4bd2a2f87..2472390086 100644
--- a/lib/buffer.js
+++ b/lib/buffer.js
@@ -199,8 +199,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))