---
title: "Using Hermes’s Quicksort to run Doom: A tale of JavaScript exploitation"
description: "A fuzzer-found bug in Hermes's stable Quicksort let a comparator callback grow the array during Array.prototype.sort, so the fixed-size index vector was read out of bounds."
url: "https://swe.quest/articles/using-hermes-s-quicksort-to-run-doom-a-tale-of-javascript-exploitation-218717db846741cf"
canonical: "https://engineering.fb.com/2022/07/20/security/hermes-quicksort-to-run-doom/"
source: "Meta Engineering"
published: "2022-07-20"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 12
tags: ["vulnerability-research","runtimes","javascript","memory-safety","c-cpp"]
---

# Using Hermes’s Quicksort to run Doom: A tale of JavaScript exploitation

A post on [Meta Engineering](https://swe.quest/sources/meta.md), published 2022-07-20, 12 min read, Deep dive. Original: [https://engineering.fb.com/2022/07/20/security/hermes-quicksort-to-run-doom/](https://engineering.fb.com/2022/07/20/security/hermes-quicksort-to-run-doom/)

## Summary

A fuzzer-found bug in Hermes's stable Quicksort let a comparator callback grow the array during Array.prototype.sort, so the fixed-size index vector was read out of bounds. Meta's security team escalated it to arbitrary read/write. They underflowed the unsigned j index to swap values outside the vector, groomed adjacent mmap'd ArrayBuffer allocations, and corrupted a malloc chunk size to get overlapping buffers. They then reclaimed one buffer as a GenGC heap segment so ArrayBuffer data pointers could be overwritten. The escalation raised the bounty from a typical $500–$3,000 to $12,000, and the exploit was demonstrated by running Doom inside Hermes.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Vulnerability research](https://swe.quest/tags/vulnerability-research.md) (Security)
- [Runtimes & VMs](https://swe.quest/tags/runtimes.md) (Compilers & runtimes)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)
- [Memory safety](https://swe.quest/tags/memory-safety.md) (Security)
- [C & C++](https://swe.quest/tags/c-cpp.md) (Languages)

## Prerequisites

- heap exploitation basics ([easy posts on Vulnerability research](https://swe.quest/tags/vulnerability-research.md?difficulty=easy))
- malloc and mmap internals
- JavaScript engine object layout ([easy posts on Runtimes & VMs](https://swe.quest/tags/runtimes.md?difficulty=easy))
- quicksort algorithm ([easy posts on Algorithms](https://swe.quest/tags/algorithms.md?difficulty=easy))

## Keywords

Hermes, Array.prototype.sort, Quicksort, ArrayBuffer, GenGC, AddressSanitizer, Meta Bug Bounty, Doom

## Related posts

- [Bun v1.0.20](https://swe.quest/articles/bun-v1-0-20-4c5d451d499e769b.md): Bun · 2023-12-24 · Medium · 6 min read · JavaScript, Runtimes & VMs, Memory management, Performance engineering
  Bun v1.0.20 cuts memory usage in node:fs async operations by avoiding redundant cross-thread string clones.
- [Turbocharging V8 with mutable heap numbers](https://swe.quest/articles/turbocharging-v8-with-mutable-heap-numbers-d32025b1d5ea1f1c.md): V8 · 2025-02-25 · Hard · 5 min read · Runtimes & VMs, Compilers, JavaScript, Performance engineering, Memory management
  V8 eliminated a performance cliff in JetStream2's async-fs benchmark caused by a custom Math.random whose \`seed\` lives in a ScriptContext slot.
- [Bun v1.0.21](https://swe.quest/articles/bun-v1-0-21-862b3088d30db391.md): Bun · 2024-01-02 · Medium · 10 min read · JavaScript, Runtimes & VMs, Memory management, SQLite
  Bun v1.0.21 fixes 33 bugs and focuses on memory: blob.arrayBuffer() now uses copy-on-write virtual memory mappings for blobs of 8 MB or more (1 MB with --smol), so 100 copies of a 128 MB blob use 192 MB instead of 12.9 GB. bun:sqlite now reports SQLite's memory to the garbage collector, cutting usage 4x for 100,000 prepared statements, and throws SQLiteError with extended error codes and messages.
- [Bun v1.1.7](https://swe.quest/articles/bun-v1-1-7-443b16215b4eb538.md): Bun · 2024-05-03 · Medium · 7 min read · JavaScript, Runtimes & VMs, Debugging
  Bun v1.1.7 fixes 28 bugs and adds glob patterns in package.json workspaces (via Bun.Glob), asymmetric matcher support in expect.extend's this.equals, and a working bunx --version.
- [Bun v0.6.9](https://swe.quest/articles/bun-v0-6-9-0635261452349fca.md): Bun · 2023-06-13 · Medium · 3 min read · JavaScript, Runtimes & VMs, Memory management
  Bun v0.6.9 focuses on memory reductions: zero-copy string Response bodies in Bun.serve() and Response (60 MB vs Deno's 425 MB and Node's 1414 MB after 1000 responses of a 12 MB string), 50% less memory for cold bun install, and fixed leaks when importing modules.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
