diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2015-03-18 21:20:23 +0300 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2015-03-18 22:06:20 +0300 |
commit | fe0f015c5159633127e268ebfc5db121883bc35c (patch) | |
tree | 51db772d079debb44e740fca89985571cde65755 /src/node_crypto_bio.h | |
parent | 2b63bcd247362ec5eb46e235a0eec68d7724a6d7 (diff) |
src: fix crypto bio integer wraparound on 32 bits
Fix a bug where a size_t was negated and passed to a function that takes
an int64_t. It works by accident when sizeof(size_t) == sizeof(int64_t)
but it causes the value to underflow when size_t is a 32 bits type.
v8::Isolate::AdjustAmountOfExternalAllocatedMemory() is the function I'm
talking about. The goal of that call is to tell V8 that some memory has
been freed but due to that underflow, we were actually reporting that we
had just allocated gigabytes of memory. It set off a garbage collector
frenzy and essentially brought the VM to a standstill.
Fixes: https://github.com/iojs/io.js/issues/1188
PR-URL: https://github.com/iojs/io.js/pull/1192
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Diffstat (limited to 'src/node_crypto_bio.h')
-rw-r--r-- | src/node_crypto_bio.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/node_crypto_bio.h b/src/node_crypto_bio.h index 5c38f1baac7..c4f2923675e 100644 --- a/src/node_crypto_bio.h +++ b/src/node_crypto_bio.h @@ -107,8 +107,10 @@ class NodeBIO { ~Buffer() { delete[] data_; - if (env_ != nullptr) - env_->isolate()->AdjustAmountOfExternalAllocatedMemory(-len_); + if (env_ != nullptr) { + const int64_t len = static_cast<int64_t>(len_); + env_->isolate()->AdjustAmountOfExternalAllocatedMemory(-len); + } } Environment* env_; |