istanbuljs / nyc

the Istanbul command line interface
https://istanbul.js.org/
ISC License
5.61k stars 359 forks source link

Large ES6 arrays parsed with Babel cause JavaScript Heap Overflows #1443

Open jroose opened 2 years ago

jroose commented 2 years ago

Link to bug demonstration repository

https://github.com/jroose/nyc_out_of_heap_mem

Expected Behavior

Doesn't throw a JavaScript heap overflow error.

Observed Behavior

Throws a JavaScript heap overflow error.

Troubleshooting steps

Environment Information

./node_modules/.bin/nyc ./node_modules/.bin/mocha --require @babel/register --reporter spec random_data.js

# Linus Sebastian lies.  Framework laptops are crumby hipster laptops (at least when you install Ubuntu).
alaric@WanderingHipster:~/.local/src/nyc_heap_issue$ ./node_modules/.bin/nyc ./node_modules/.bin/mocha --require @babel/register --reporter spec random_data.js 

<--- Last few GCs --->

[16213:0x559d5a2fc260]    28860 ms: Scavenge 2046.3 (2050.4) -> 2045.7 (2050.9) MB, 7.7 / 0.0 ms  (average mu = 0.356, current mu = 0.328) allocation failure 
[16213:0x559d5a2fc260]    29420 ms: Mark-sweep 2046.5 (2050.9) -> 2045.3 (2050.9) MB, 479.9 / 0.0 ms  (+ 252.0 ms in 38 steps since start of marking, biggest step 8.8 ms, walltime since start of marking 761 ms) (average mu = 0.349, current mu = 0.343) all

<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x7ff621d303b9]
Security context: 0x0f07e50db9a1 <JSObject>
    1: SourceMapConsumer_allGeneratedPositionsFor [0x7eed5803d79] [/home/alaric/.local/src/nyc_heap_issue/node_modules/source-map/lib/source-map-consumer.js:~178] [pc=0x198cb0e079fb](this=0x3c908eb40281 <BasicSourceMapConsumer map = 0x34da24a4af29>,0x016a141139d9 <Object map = 0x3f1b8c250a9>)
    2: /* anonymous */(aka /* anonymous */) [0x3c908eb40169] [/hom...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0x7ff6210815fc node::Abort() [/lib/x86_64-linux-gnu/libnode.so.72]
 2: 0x7ff620fb1fdc  [/lib/x86_64-linux-gnu/libnode.so.72]
 3: 0x7ff621242a2a v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/lib/x86_64-linux-gnu/libnode.so.72]
 4: 0x7ff621242de4 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/lib/x86_64-linux-gnu/libnode.so.72]
 5: 0x7ff6213f5259  [/lib/x86_64-linux-gnu/libnode.so.72]
 6: 0x7ff621405b16 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/lib/x86_64-linux-gnu/libnode.so.72]
 7: 0x7ff62140695e v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/lib/x86_64-linux-gnu/libnode.so.72]
 8: 0x7ff621408cfd v8::internal::Heap::AllocateRawWithLightRetry(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/lib/x86_64-linux-gnu/libnode.so.72]
 9: 0x7ff621408d69 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/lib/x86_64-linux-gnu/libnode.so.72]
10: 0x7ff6213cdab3 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/lib/x86_64-linux-gnu/libnode.so.72]
11: 0x7ff621723277 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/lib/x86_64-linux-gnu/libnode.so.72]
12: 0x7ff621d303b9  [/lib/x86_64-linux-gnu/libnode.so.72]
----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |                   
----------|---------|----------|---------|---------|-------------------
Aborted (core dumped)
jroose commented 2 years ago

random_data.js is just 500 lines of this:

var normal_dist = [
-3.8906,-3.6153,-3.4808,-3.3896,-3.3201,-3.2636,-3.2160,-3.1747,-3.1382,-3.1054,-3.0757,-3.0485,-3.0233,-3.0000,-2.9781,-2.9576,-2.9383,-2.9200,-2.9027,-2.8861,
-2.8704,-2.8553,-2.8408,-2.8269,-2.8135,-2.8006,-2.7882,-2.7762,-2.7646,-2.7533,-2.7424,-2.7317,-2.7214,-2.7114,-2.7016,-2.6921,-2.6828,-2.6738,-2.6649,-2.6563,
-2.6479,-2.6396,-2.6315,-2.6236,-2.6159,-2.6083,-2.6008,-2.5935,-2.5863,-2.5793,-2.5724,-2.5656,-2.5589,-2.5523,-2.5459,-2.5395,-2.5333,-2.5271,-2.5211,-2.5151,
-2.5092,-2.5034,-2.4977,-2.4921,-2.4865,-2.4810,-2.4756,-2.4703,-2.4650,-2.4598,-2.4547,-2.4496,-2.4446,-2.4397,-2.4348,-2.4300,-2.4252,-2.4205,-2.4158,-2.4112,
...
2.4112,2.4158,2.4205,2.4252,2.4300,2.4348,2.4397,2.4446,2.4496,2.4547,2.4598,2.4650,2.4703,2.4756,2.4810,2.4865,2.4921,2.4977,2.5034,2.5092,
2.5151,2.5211,2.5271,2.5333,2.5395,2.5459,2.5523,2.5589,2.5656,2.5724,2.5793,2.5863,2.5935,2.6008,2.6083,2.6159,2.6236,2.6315,2.6396,2.6479,
2.6563,2.6649,2.6738,2.6828,2.6921,2.7016,2.7114,2.7214,2.7317,2.7424,2.7533,2.7646,2.7762,2.7882,2.8006,2.8135,2.8269,2.8408,2.8553,2.8704,
2.8861,2.9027,2.9200,2.9383,2.9576,2.9781,3.0000,3.0233,3.0485,3.0757,3.1054,3.1382,3.1747,3.2160,3.2636,3.3201,3.3896,3.4808,3.6153,3.8906
];
jroose commented 2 years ago

Still fails after running npm update.