Heap Feng-Shui to Exploit JavaScriptCore Spread Overflow
JavaScriptCore will allocate a JSFixedArray for every spread operand of the array literal (in slow_path_spread). As such, roughly 4 billion JSValues will have to be allocated, taking up 32 GiB in RAM. To exploit the bug, the author allocates 100 JSArrays of size 0x40000 and roots them, allocates 100 JSArrays of size 0x40000, where only every second one is rooted, allocates a larger JSArray and an ArrayBuffer of the same size, allocates 4 GiB of padding using JSArrays, and triggers the bug by concatenating JSArrays with a combined size of 232 + 0x40000 (containing the repeated byte 0x41). This increases the size of the victim array to the sprayed value (0x4141414141414141), so that it overlaps with the victim ArrayBuffer. This yields the fakeobj and addrof primitives which can then be used to write code to a JIT page and jump to it.