Skip to content

Commit 33e25b6

Browse files
src: call V8::ExternalMemoryAccounter::Update instead of
`V8::ExternalMemoryAccounter::Increase` to report memory difference to V8 Calling `V8::ExternalMemoryAccounter::Increase` with a signed integer on 32-bit platforms causes instances where GC inside GC takes place leading to a crash in certain cases. During GC, native objects are destructed. In destructor for `CompressionStream` class used by zlib, memory release information is passed onto `V8::ExternalMemoryAccounter::Increase()` instead of `V8::ExternalMemoryAccounter::Decrease()` which triggers V8's memory limits, thus triggering GC inside GC which leads to crash. Bug initially introduced in commit 1d5d7b6 For full report see https://hackerone.com/reports/3302484
1 parent 7beb6fa commit 33e25b6

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/node_mem-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void* NgLibMemoryManager<Class, T>::ReallocImpl(void* ptr,
5959
// Environment*/Isolate* parameter and call the V8 method transparently.
6060
const int64_t new_size = size - previous_size;
6161
manager->IncreaseAllocatedSize(new_size);
62-
manager->env()->external_memory_accounter()->Increase(
62+
manager->env()->external_memory_accounter()->Update(
6363
manager->env()->isolate(), new_size);
6464
*reinterpret_cast<size_t*>(mem) = size;
6565
mem += sizeof(size_t);

src/node_zlib.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
644644
if (report == 0) return;
645645
CHECK_IMPLIES(report < 0, zlib_memory_ >= static_cast<size_t>(-report));
646646
zlib_memory_ += report;
647-
AsyncWrap::env()->external_memory_accounter()->Increase(
647+
AsyncWrap::env()->external_memory_accounter()->Update(
648648
AsyncWrap::env()->isolate(), report);
649649
}
650650

0 commit comments

Comments
 (0)