Skip to content
Memory corruption Disclosed report Advanced CVE-2025-0238

AddressSanitizer: heap-use-after-free on nsLineBreaker::FlushCurrentWord() after malloc failure

When memory allocation fails inside nsLineBreaker::FlushCurrentWord(), the code continues to use a buffer that was not successfully resized, leading to a heap-use-after-free. An attacker could trigger this by repeatedly calling insertLineBreak and setRangeText in a loop, causing Firefox to crash with SIGSEGV or ASan-detected use-after-free.

Irvan Kurniawan Follow

Originally disclosed on Mozilla

  • Fixed in 3 months
  • Paid in 3 months
  • Disclosed after 3 months

Created attachment 9421449 minidump_0x838d084d.txt

After run document.execCommand("insertLineBreak") and setRangeText in loop, when malloc failure on nsLineBreaker::FlushCurrentWord() in if (!breakState.AppendElements(length, mozilla::fallible)) { Firefox able to crash with SIGSEGV/SEGV_ACCERR with changing address, sometimes SIGILL/ILL_ILLOPN with changing top stack, and ASan heap-use-after-free on nsLineBreaker::FlushCurrentWord() with READ of size 4 (32-bit) and READ of size 8 (64-bit) ASan build

Tested on:

  • Firefox 129.0.2 (32-bit)
  • Firefox Nightly 131.0a1 (2024-08-28) (32-bit)

Steps to reproduce:

  1. Apply attached nsLineBreaker-FlushCurrentWord.patch
  2. Compile Firefox
  3. Visit attached testcase.forpatch.html
  4. Firefox crash with SIGSEGV / SEGV_ACCERR or AddressSanitizer: heap-use-after-free on ASan build

The original report as published on Mozilla's Bugzilla, by Irvan Kurniawan. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the code fails to check the return value of AppendElements with fallible allocation, then proceeds to read from the buffer as if the resize succeeded, causing a use-after-free.

Impact

An attacker could crash the browser and potentially exploit the use-after-free for code execution, though the report only demonstrates a crash.

What the attacker needed

Victim visits a crafted HTML page; memory allocation failure occurs

The fix

The code should check the return value of the fallible AppendElements call and handle allocation failure without using the invalidated buffer.

How it was found

  1. Apply the provided patch to nsLineBreaker::FlushCurrentWord
  2. Compile Firefox
  3. Visit the attached testcase HTML file
  4. Observe the crash (SIGSEGV or ASan heap-use-after-free)

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a program needs more memory, it asks the system for some. If the system says no, the program should handle that gracefully. Here, Firefox ignored the failure and kept using the old, now-invalid memory, which can crash the browser or let an attacker corrupt memory.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by Irvan Kurniawan

View all

72 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.