Skip to content
DoS Disclosed report Intermediate CVE-2023-32209

persistent browser DoS via favicon containing a small JPEG images that list their image dimensions as large

A tiny JPEG file whose header claims very large image dimensions causes Firefox to try to allocate an enormous amount of memory when decoding it. This crashes the sandboxed tab, and when the image is previewed in the Network Monitor it crashes the whole browser after the OOM killer terminates it.

sam.z.ezeh Follow

Originally disclosed on Mozilla

  • Fixed in 11 months
  • Paid in 6 months
  • Disclosed after 11 months

Summary

Upon loading a jpeg image with large dimensions, Firefox attempts to allocate a large amount of memory which in certain contexts can causes effects outside of the sandbox, causing Firefox to crash.

System configuration

  • Firefox Developer Edition 100.0b9 (64-bit)
  • Linux kernel version 5.17.4

Description

I was able create a single pixel image file of size 1.4kb. I then modified the binary image file data to list the dimensions of the image as 61680 x 61680. In order to render this image, Firefox attempts to allocate memory to store this image.

When a page that displays this image is rendered, the sandboxed tab crashes. However, when the image is viewed inside the Network Monitor, the Firefox application also crashes after it is killed by the OOM-killer.

Proof of Concept

  1. Loading the following image in the browser will cause the tab to crash: https://exploit-py.herokuapp.com/tiny.jpg
  2. Opening the Network Monitor and previewing the image (e.g. by hovering over the image name) will cause Firefox to crash.
sam@samtop ~ % firefox-developer-edition 
ATTENTION: default value of option mesa_glthread overridden by environment.
ATTENTION: default value of option mesa_glthread overridden by environment.
ATTENTION: default value of option mesa_glthread overridden by environment.
Corrupt JPEG data: premature end of data segment
Exiting due to channel error.
Exiting due to channel error.
Exiting due to channel error.
[1]    47893 killed     firefox-developer-edition
firefox-developer-edition  11.74s user 21.24s system 104% cpu 31.489 total
137 sam@samtop ~ %  

Relevant code

In image/decoders/iccjpeg.c https://hg.mozilla.org/mozilla-central/file/6e268f45bed2487cce05cfae5cabb7c1c8f415a6/image/decoders/iccjpeg.c#l159

C++
/* Allocate space for assembled data */
icc_data = (JOCTET*)malloc(total_length * sizeof(JOCTET));
if (icc_data == NULL) {
  return FALSE; /* oops, out of memory */
}

In image/decoders/nsJPEGDecoder.cpp https://hg.mozilla.org/mozilla-central/file/6e268f45bed2487cce05cfae5cabb7c1c8f415a6/image/decoders/nsJPEGDecoder.cpp#l839

C++
// Round up to multiple of 256 bytes.
const size_t roundup_buflen = ((new_backtrack_buflen + 255) >> 8) << 8;
JOCTET* buf = (JOCTET*)realloc(decoder->mBackBuffer, roundup_buflen);
// Check for OOM
if (!buf) {
  decoder->mInfo.err->msg_code = JERR_OUT_OF_MEMORY;
  my_error_exit((j_common_ptr)(&decoder->mInfo));
}

In media/libjpeg/jdhuff.c https://searchfox.org/mozilla-central/source/media/libjpeg/jdhuff.c#354-373

C++
no_more_bytes:
    /* We get here if we've read the marker that terminates the compressed
     * data segment.  There should be enough bits in the buffer register
     * to satisfy the request; if so, no problem.
     */
    if (nbits > bits_left) {
      /* Uh-oh.  Report corrupted data to user and stuff zeroes into
       * the data stream, so that we can produce some kind of image.
       * We use a nonvolatile flag to ensure that only one warning message
       * appears per data segment.
       */
      if (!cinfo->entropy->insufficient_data) {
        WARNMS(cinfo, JWRN_HIT_MARKER);
        cinfo->entropy->insufficient_data = TRUE;
      }
      /* Fill the buffer with zero bits */
      get_buffer <<= MIN_GET_BITS - bits_left;
      bits_left = MIN_GET_BITS;
    }
  }

WARNMS(cinfo, JWRN_HIT_MARKER) generates the Corrupt JPEG data: premature end of data segment message.

In general, when Linux is configured to overcommit memory (this is the default configuration), malloc doesn't return 0 when there is no memory left.

It is also possible for the OOM killer to kill a process that isn't Firefox that happens to be vital to the function of the Operating System causing an OS crash.

Notes

In Chromium, upon loading this image does not crash. On chromium in certain contexts, the image with fail to load and is displayed as an invalid image file. In other contexts, the image will correctly be displayed as single pixel white image. This happens without causing excessive memory usage.

It's possible that images loaded from inside sandboxed tabs should not be loaded outside of the sandbox.

The original report as published on Mozilla's Bugzilla, by sam.z.ezeh. 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 JPEG decoder allocates memory based on the dimensions declared in the file header without checking them against the actual amount of image data present.

Impact

A page displaying the image crashes the tab, and previewing it in the Network Monitor crashes the whole browser; the OOM killer could also terminate other processes, potentially destabilising the operating system.

What the attacker needed

Victim loads a page with the crafted image; Linux with default memory overcommit

How it was found

  1. Load the crafted image in the browser, which crashes the tab.
  2. Open the Network Monitor and preview the image, which crashes the whole browser.

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.

An image file stores its width and height in its header, and the browser trusts those numbers when deciding how much memory to reserve. Here the header claimed a huge size while the file itself was tiny, so the browser tried to reserve far more memory than the machine had. The operating system then killed the browser to protect itself.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.