Skip to content
Memory corruption Write-up Advanced

How 5 Characters of C Code Put Millions of Apps at Risk

Two memory safety bugs in audio decoding libraries: a heap buffer overflow in stb_vorbis caused by truncating a size_t product to int, and an out-of-bounds read in libmodplug from a missing lower-bound check. An attacker could trigger the overflow with a crafted Ogg file, potentially leading to arbitrary code execution, while the read could leak a byte of adjacent memory.

medium.com

Published on medium.com

Cve

Perparim Mjeku, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

Two memory safety bugs in audio decoding libraries are covered here: CVE-2026-89266 in stb_vorbis.c and CVE-2026-75904 in libmodplug. Both libraries parse untrusted binary input, and both are widely depended on by applications that rarely think about them.

stb_vorbis.c decodes Ogg Vorbis audio. It is a single C file with no build system, no package manager entry and no update mechanism. Projects copy it into their source tree and forget about it. It sits somewhere in the dependency tree of most game engines, media converters and audio tools.

libmodplug is a proper system package that ships on Debian, Ubuntu, Fedora and Gentoo, and is a dependency of GStreamer's module playback pipeline. Default music players, file manager audio previews and media indexing daemons inherit it.

From the original on medium.com

Setup

The affected and fixed versions are:

CVE Library Affected Patched Weakness CVSS Disclosed
CVE-2026-89266 stb_vorbis ≤ 1.22 v1.23 CWE-190 8.2 (High) Sep 12, 2026
CVE-2026-75904 libmodplug ≤ [redacted] v0.8.9.2 CWE-125 3.3 (Low) Aug 18, 2026

No accounts, roles or special tooling are involved. The precondition in both cases is that the target application decodes attacker-supplied files through the vulnerable library: an .ogg file for stb_vorbis, a MIDI or tracker module file for libmodplug.

Finding it

The stb_vorbis bug is a type narrowing. start_decoder() parses a Vorbis stream's codebook header. Two fields, entries and dimensions, are read directly from the stream data and multiplied together to size the allocation for codebook multiplicands. The product is computed as a size_t, which is 64-bit on most modern systems, but before it reaches the allocator it is truncated to a signed int, which is 32-bit. When the product exceeds INT_MAX the value wraps, the allocator receives a much smaller number, a tiny buffer is allocated, and the decoder then writes the full, un-truncated amount of data into it.

The root cause is five characters wide: the cast from size_t to int.

The libmodplug bug is subtler. pat_smplooped() in src/load_pat.cpp looks up a sample number in a 191-byte static array called pat_loops to decide whether a note should loop. The bounds check validates only the upper limit, then subtracts one. A zero sample number therefore indexes one byte before the array. Zero is not an edge case: it is the default. The smpno field of a parsed MIDI event starts at zero and is only overwritten when a program-change message assigns an instrument, so any note event that fires before that assignment carries a zero index straight into the function.

Exploitation

Step 1: Control the codebook fields (CVE-2026-89266)

Both entries and dimensions come from the Vorbis stream, so an attacker controls them. The allocation and the write loop look like this:

C
size_t total = entries * dimensions;int alloc_size = (int)total;            c->multiplicands = malloc(alloc_size * sizeof(codetype));
C
for (int i = 0; i < entries * dimensions; i++)    c->multiplicands[i] = /* decoded value */;  // writes past end

The first block computes the product as size_t, truncates it to int for the allocation, and passes the truncated size to malloc. The second block iterates over the full, un-truncated product and writes each decoded codebook value, so the writes continue past the end of the undersized buffer.

Step 2: Shape the overflow

The attacker chooses entries and dimensions values that wrap to a specific small integer. The overflow geometry, meaning how far past the buffer the writes go and what data lands there, is fully controllable. The attacker shapes the heap layout and writes over adjacent heap structures: function pointers, vtable entries, allocator metadata.

Step 3: Deliver the file

The trigger is the simplest possible attack surface: open an audio file. Any application that decodes untrusted .ogg files through stb_vorbis ≤ 1.22 is exposed. That includes game asset pipelines, media upload handlers, audio preview features, voice chat decoders and mod loading systems.

Step 4: Reach the zero index (CVE-2026-75904)

The vulnerable function is:

C
static int pat_smplooped(int smpno) {    if (smpno >= MAXSMP) return 0;    return pat_loops[smpno - 1];  }

The check rejects indices at or above MAXSMP but says nothing about the lower bound. With smpno equal to zero, the access becomes pat_loops[-1], one byte before the array.

Step 5: Build the minimal file

A MIDI file as small as 32 bytes is enough to walk the path:

Text
ModPlug_Load → CSoundFile::ReadMID → MID_ReadPatterns → pat_smplooped(0)

Any note event that fires before a program-change message assigns an instrument carries a zero index into pat_smplooped.

Root cause

Both bugs share a pattern: a C library parsing an untrusted binary format, with arithmetic that was never validated against the full range of its inputs.

In stb_vorbis, the narrowing conversion from size_t to int turns a large allocation into a small one. The multiplication is done in a wide type, but the result is silently truncated before it is used as a size, and the write loop still uses the wide product. Nothing between the parse and the allocation checks that the product fits in an int.

In libmodplug, the bounds guard is one-sided. Checking only smpno >= MAXSMP leaves the lower bound open, and the subsequent smpno - 1 turns the unchecked zero into a negative index. The default value of the field makes the bad index reachable.

Neither bug is complex. Both sat in widely shipped code for years.

Impact

For CVE-2026-89266, this is not a theoretical crash. Heap buffer overflows with controlled write data are a well-understood path to arbitrary code execution. The attacker shapes the heap layout and writes decoded codebook values over adjacent heap structures such as function pointers, vtable entries and allocator metadata.

The blast radius is unusually wide because stb_vorbis has no package manager, no update channel and no way to know who is using it. Every project that copied stb_vorbis.c into its source tree must find and replace the file manually. The nothings/stb repository has tens of thousands of stars, but that number drastically understates real-world adoption, because the entire value proposition of STB is to copy one file into a project. Most consumers did exactly that, years ago, and never looked back. The library shows up in indie game engines, commercial audio tools, Android and iOS apps, embedded devices, CI pipelines that process user-uploaded media, and countless internal tools. There is no apt upgrade that fixes this; each project is its own island.

For CVE-2026-75904, the impact is an out-of-bounds read, not a write. It reads exactly one byte from whatever static storage the linker placed adjacent to pat_loops. There is no code execution and usually no crash. The leaked byte determines whether a note loops, so adjacent static data silently influences playback behaviour. The severity is low and appropriately so, but low severity is not the same as no consequence. In an information-disclosure context even a single-byte read primitive has value, especially one that does not crash and leaves no trace that it fired. It can serve as a building block in a larger chain.

Its blast radius is narrower in one sense and wider in another. libmodplug ships on Debian, Ubuntu, Fedora and Gentoo, and is a dependency of GStreamer's module playback pipeline, so default music players, file manager audio previews and media indexing daemons all inherit the bug. The attack surface is narrower because MIDI and tracker module files are niche formats, but for environments that do process them, such as game development, demoscene archives, retro music platforms and media conversion pipelines, libmodplug is the standard library.

Fix

stb_vorbis was patched in v1.23. Because the library has no distribution channel, the fix only reaches a project when someone manually replaces stb_vorbis.c in the source tree.

libmodplug was patched in v0.8.9.2. Unlike stb_vorbis, the fix propagates through normal package manager channels, and most Linux systems will pick it up through routine updates.

Variants to test

  1. Other size computations narrowed to int. Look for products of two or more stream-controlled fields that are computed in size_t and then cast to int before an allocation.
  2. One-sided bounds checks followed by subtraction. Search parsers for guards of the form if (x >= MAX) return followed by an array access at x - 1.
  3. Default-initialised fields used before assignment. In MIDI and tracker parsers, check whether note events that precede a program-change message carry a zero instrument index into lookup tables.
  4. Vendored single-file libraries. Inventory projects for copied-in C files such as stb_vorbis.c that have no package manager entry.
  5. Media parsers early in the pipeline. Test upload handlers, preview generators and indexing daemons that process untrusted audio with no sandboxing.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 15 min read.

What happened, in plain words

Two bugs were found in pieces of software that read audio files. Both bugs are in C code, and both are the kind of mistake that lets a malicious file do things to a program that the program's author never intended.

One bug is in a file called stb_vorbis.c, which reads a type of audio file called Ogg Vorbis (the .ogg files you may have seen). This file is not installed like a normal program. Developers copy it into their own projects, like photocopying a recipe into your own cookbook, and then forget about it. Because of that, there is no central place to send out a fix. The bug is rated 8.2 on a 10-point scale called CVSS, which means High.

The other bug is in a library called libmodplug, which reads MIDI files and tracker module files (formats used for music, especially in games and the demoscene). This one is rated 3.3, which means Low. It is a smaller bug, but it follows the same pattern: C code reading a file from an untrusted source, with arithmetic that was never checked properly.

From the original on medium.com

Both bugs were sitting in widely shipped code for years. This article walks through what each bug is, how it works at the level of the code, and why the reach of each one is bigger or smaller than you might guess.

Before going further, a few words that will come up constantly.

  • C is a programming language. It is fast and gives the programmer direct control over the computer's memory. That control is also why mistakes in C can be dangerous: if you tell C to write data somewhere it should not, it will usually just do it.
  • Memory here means the working space a program uses while it runs. Think of it as a long row of numbered boxes, each holding a small amount of data. A program asks for boxes, writes into them, and reads from them.
  • A buffer is a run of boxes set aside for one purpose, for example to hold the contents of an audio file while it is being decoded.
  • A library is a bundle of code that other programs use so they do not have to write everything themselves. When your music player opens an .ogg file, it is almost certainly calling a library to do the decoding.
  • A memory safety bug is a mistake where a program reads or writes memory it was not supposed to touch. Two common kinds appear here: a buffer overflow (writing past the end of a buffer) and an out-of-bounds read (reading from just outside a buffer).
  • CVE stands for Common Vulnerabilities and Exposures. It is a public ID number given to a known security bug so that people can talk about it unambiguously. The two here are CVE-2026-89266 and CVE-2026-75904.
  • CVSS is a scoring system from 0 to 10 that tries to express how serious a bug is. Higher is worse.
  • CWE is a catalogue of weakness types. CWE-190 means integer overflow (a number getting too big for its container and wrapping around). CWE-125 means out-of-bounds read.

The two bugs at a glance

CVE Library Affected versions Fixed in Weakness CVSS Disclosed
CVE-2026-89266 stb_vorbis ≤ 1.22 v1.23 CWE-190 8.2 (High) 12 Sep 2026
CVE-2026-75904 libmodplug ≤ [redacted] v0.8.9.2 CWE-125 3.3 (Low) 18 Aug 2026

There are no accounts, no logins and no special tools involved in either case. The only precondition is that the target program decodes a file the attacker supplies: an .ogg file for stb_vorbis, or a MIDI or tracker module file for libmodplug.

The first bug: CVE-2026-89266 in stb_vorbis

What stb_vorbis is and why it is everywhere

stb_vorbis.c is a single C file that decodes Ogg Vorbis audio. It has no build system (no script that compiles it), no entry in a package manager (the tool that installs and updates software for you), and no update mechanism. Developers copy the file into their project's source code and move on.

That file sits somewhere in the dependency tree of most game engines, media converters and audio tools. A dependency tree is the chain of libraries a program relies on: your program uses library A, which uses library B, which uses library C. You may never have heard of C, but it is running inside your program.

The mechanism: a number that gets cut down to size

To understand this bug you need one idea: numbers in C come in different sizes, and each size has a maximum.

  • A size_t is an unsigned (non-negative) integer type that is 64 bits wide on most modern systems. It can hold very large values.
  • An int is a signed integer type that is 32 bits wide. It has a maximum value called INT_MAX.

When a number that is too big for its container is forced into it, the value wraps: it does not error out, it silently becomes a different, usually much smaller, number. This is called an integer overflow or truncation. A useful comparison: a car odometer with six digits rolls from 999999 back to 000000. The car did not stop, but the number no longer means what you think.

The function start_decoder() parses the header of a Vorbis stream. Inside that header are two fields, entries and dimensions, which are read directly from the file. They are multiplied together to work out how much memory to reserve for a table of values called codebook multiplicands.

The multiplication is done as a size_t, so it can be large. But before the result reaches the memory allocator, it is cast (converted) to a signed int. If the product is bigger than INT_MAX, the value wraps. The allocator is handed a much smaller number than the real one, so it reserves a tiny buffer. The decoder then writes the full, un-truncated amount of data into that tiny buffer.

The root cause is five characters wide: the cast from size_t to int.

Here is the allocation code as it appears in the report:

C
size_t total = entries * dimensions;int alloc_size = (int)total;            c->multiplicands = malloc(alloc_size * sizeof(codetype));

Line by line:

  1. size_t total = entries * dimensions; multiplies the two values taken from the file and stores the result in a 64-bit unsigned variable called total. At this point the number is correct and can be large.
  2. int alloc_size = (int)total; converts total into a 32-bit signed integer. The (int) is the cast. If total is larger than INT_MAX, the value wraps and alloc_size becomes a small number, possibly even negative.
  3. c->multiplicands = malloc(alloc_size * sizeof(codetype)); asks the allocator (malloc) for memory. sizeof(codetype) is the size of one element. Because alloc_size is small, the buffer is small.

And here is the loop that writes into that buffer:

C
for (int i = 0; i < entries * dimensions; i++)    c->multiplicands[i] = /* decoded value */;  // writes past end

Line by line:

  1. for (int i = 0; i < entries * dimensions; i++) loops once for every element of the full, un-truncated product. This is the real number of values the file says it contains, which can be far larger than the buffer.
  2. c->multiplicands[i] = /* decoded value */; writes each decoded value into the buffer at position i. Once i passes the end of the small buffer, the writes land in memory beyond it. The comment // writes past end marks exactly that.

Both entries and dimensions come from the file, so an attacker controls them. The overflow geometry, meaning how far past the buffer the writes go and what data lands there, is fully controllable.

Why this matters: from a crash to running code

This is not a theoretical crash. A heap buffer overflow with controlled write data is a well-understood path to arbitrary code execution, which means the attacker can make the program run instructions of their choosing.

A quick word on the heap: when a program needs memory while it is running, it asks the operating system for it, and that pool of memory is called the heap. It holds data structures the program uses, including things like function pointers (addresses of functions to call) and vtable entries (tables used to dispatch methods in object-oriented code).

The attacker shapes the heap layout by choosing entries and dimensions values that wrap to a specific small integer, then writes decoded codebook values over adjacent heap structures such as function pointers, vtable entries and allocator metadata.

The trigger is the simplest possible attack surface: open an audio file. Any application that decodes untrusted .ogg files through stb_vorbis 1.22 or earlier is exposed. That includes game asset pipelines, media upload handlers, audio preview features, voice chat decoders and mod loading systems.

Why the blast radius is enormous

stb_vorbis has no package manager. No update channel. No way to know who's using it. Every project that copied stb_vorbis.c into its source tree must find and replace the file manually.

The STB collection is one of the most widely vendored pieces of open-source C code in existence. Vendored means the code is copied into a project rather than installed as a shared package. The nothings/stb repository on GitHub has tens of thousands of stars, but that number drastically understates real-world adoption. The entire value proposition of STB is "copy this one file into your project". Most consumers did exactly that, years ago, and never looked back.

The library shows up in indie game engines, commercial audio tools, Android and iOS apps, embedded devices, CI pipelines that process user-uploaded media, and countless internal tools. There is no apt upgrade that fixes this. apt is the package manager on Debian and Ubuntu systems; apt upgrade updates installed packages. It cannot help here, because stb_vorbis was never installed as a package. Each project is its own island.

The second bug: CVE-2026-75904 in libmodplug

What libmodplug is

libmodplug reads MIDI files and tracker module files. A MIDI file is a small file of instructions for a synthesiser: which note to play, when, and with which instrument. A tracker module is a similar format used heavily in the demoscene (a subculture of programmers and artists who make small audio-visual programs).

Unlike stb_vorbis, libmodplug is a proper system package. It ships on Debian, Ubuntu, Fedora and Gentoo, and it is a dependency of GStreamer's module playback pipeline. GStreamer is a framework many Linux programs use to play and process media. Because of that, default music players, file manager audio previews and media indexing daemons all inherit the bug.

The mechanism: a check that only looks one way

The function pat_smplooped() in src/load_pat.cpp looks up a sample number in a 191-byte static array called pat_loops to decide whether a note should loop. A static array is a fixed-size block of memory that exists for the whole life of the program. An array is a numbered list of values; in C, the first element is at index 0, and you access element n with array[n].

The bounds check only validates the upper limit: the index must not exceed MAXSMP. Then it subtracts one.

C
static int pat_smplooped(int smpno) {    if (smpno >= MAXSMP) return 0;    return pat_loops[smpno - 1];  }

Line by line:

  1. static int pat_smplooped(int smpno) { declares a function that takes a sample number smpno and returns an integer.
  2. if (smpno >= MAXSMP) return 0; rejects any index at or above MAXSMP. This is the upper-bound check. It says nothing about values below zero.
  3. return pat_loops[smpno - 1]; looks up the array at position smpno - 1. If smpno is 0, this becomes pat_loops[-1], one byte before the start of the array.

Zero is not an edge case: it is the default. The smpno field of a parsed MIDI event starts at zero and is only overwritten when a program-change message assigns an instrument. Any note event that fires before that assignment carries a zero index straight into this function.

Reaching the bug with a tiny file

A MIDI file as small as 32 bytes is enough to walk the path:

Text
ModPlug_Load → CSoundFile::ReadMID → MID_ReadPatterns → pat_smplooped(0)

This is a call chain. Read it left to right:

  1. ModPlug_Load is the entry point: the program asks libmodplug to load a file.
  2. CSoundFile::ReadMID is the MIDI reader inside the library.
  3. MID_ReadPatterns reads the note patterns from the file.
  4. pat_smplooped(0) is called with a sample number of zero, which triggers the out-of-bounds read.

Any note event that fires before a program-change message assigns an instrument carries a zero index into pat_smplooped.

What the impact actually is

This is an out-of-bounds read, not a write. It reads exactly one byte from whatever static storage the linker placed adjacent to pat_loops. The linker is the tool that stitches compiled code and data together into a final program, and it decides what sits next to what in memory.

There is no code execution and usually no crash. The leaked byte determines whether a note loops, so adjacent static data silently influences playback behaviour. The severity is low, and appropriately so. But low severity is not the same as no consequence. In an information-disclosure context, even a single-byte read primitive has value, especially one that does not crash and leaves no trace that it fired. It can serve as a building block in a larger chain.

Its blast radius is narrower in one sense and wider in another. libmodplug ships on Debian, Ubuntu, Fedora and Gentoo, and is a dependency of GStreamer's module playback pipeline, so default music players, file manager audio previews and media indexing daemons all inherit the bug. The attack surface is narrower because MIDI and tracker module files are niche formats, but for environments that do process them, such as game development, demoscene archives, retro music platforms and media conversion pipelines, libmodplug is the standard library.

The pattern worth noticing

These two bugs look unrelated on the surface: different libraries, different severity, different exploitation potential. But the underlying pattern is the same: a C library parsing an untrusted binary format, with arithmetic that was never validated against the full range of its inputs.

In one case, a type narrowing from size_t to int turns a large allocation into a small one. In the other, a missing > 0 check lets a default zero walk past a bounds guard. Neither bug is complex. Both sat in widely shipped code for years.

Media parsers run early in the processing pipeline, on attacker-supplied input, often with no sandboxing. A sandbox is a restricted environment that limits what a program can do if it is compromised. The blast radius of a bug in one of these libraries is not determined by the library's name recognition; it is determined by how many applications silently linked against it and never looked at it again.

How the bugs were fixed

stb_vorbis was patched in v1.23. Because the library has no distribution channel, the fix only reaches a project when someone manually replaces stb_vorbis.c in the source tree.

libmodplug was patched in v0.8.9.2. Unlike stb_vorbis, the fix propagates through normal package manager channels, and most Linux systems will pick it up through routine updates.

Variants to test

If you are auditing code for the same kinds of mistakes, these are the patterns to look for.

  1. Other size computations narrowed to int. Look for products of two or more stream-controlled fields that are computed in size_t and then cast to int before an allocation.
  2. One-sided bounds checks followed by subtraction. Search parsers for guards of the form if (x >= MAX) return followed by an array access at x - 1.
  3. Default-initialised fields used before assignment. In MIDI and tracker parsers, check whether note events that precede a program-change message carry a zero instrument index into lookup tables.
  4. Vendored single-file libraries. Inventory projects for copied-in C files such as stb_vorbis.c that have no package manager entry.
  5. Media parsers early in the pipeline. Test upload handlers, preview generators and indexing daemons that process untrusted audio with no sandboxing.

Glossary

  • Arbitrary code execution: a situation where an attacker can make a program run instructions of their choosing.
  • Array: a numbered list of values in memory; in C the first element is at index 0.
  • Blast radius: how many programs, devices or users are affected by a bug.
  • Buffer: a block of memory set aside to hold data, such as a decoded audio file.
  • Buffer overflow: writing data past the end of a buffer, into memory that belongs to something else.
  • C: a programming language that gives direct control over memory and is widely used in libraries.
  • Cast: an explicit conversion from one data type to another, such as (int)total.
  • CI pipeline: an automated build-and-test system that runs when code changes; it may process user-uploaded files.
  • Codebook: a table used by the Vorbis audio format to decode compressed values.
  • CVE: Common Vulnerabilities and Exposures, a public ID number for a known security bug.
  • CVSS: a 0 to 10 score expressing the severity of a vulnerability.
  • CWE: a catalogue of weakness types, such as CWE-190 (integer overflow) and CWE-125 (out-of-bounds read).
  • Daemon: a background program that runs without a user interface, such as a media indexer.
  • Dependency tree: the chain of libraries a program relies on, directly or indirectly.
  • Demoscene: a subculture that produces small audio-visual programs, often using tracker music.
  • Function pointer: a variable holding the address of a function, which the program can call indirectly.
  • GStreamer: a framework used by many Linux programs to play and process media.
  • Heap: the pool of memory a program requests at run time for its data structures.
  • Information disclosure: leaking data the attacker should not be able to see.
  • Integer overflow: when a number exceeds the maximum its type can hold and wraps to a different value.
  • int: a signed 32-bit integer type in C, with a maximum value called INT_MAX.
  • Library: a bundle of code that other programs use instead of writing it themselves.
  • Linker: the tool that combines compiled code and data into a final program and decides their layout in memory.
  • malloc: the C function that asks the system for a block of memory.
  • Memory safety bug: a mistake where a program reads or writes memory it should not touch.
  • MIDI: a small file format of instructions for a synthesiser: notes, timing and instruments.
  • Out-of-bounds read: reading memory just outside the intended buffer or array.
  • Package manager: the tool that installs and updates software on a system, such as apt on Debian and Ubuntu.
  • Sandbox: a restricted environment that limits what a compromised program can do.
  • size_t: an unsigned integer type in C, 64 bits wide on most modern systems.
  • Static array: a fixed-size block of memory that exists for the whole life of the program.
  • Tracker module: a music file format used in the demoscene and games, read by libmodplug.
  • Truncation: cutting a value down to fit a smaller type, silently losing the high bits.
  • Vendored code: code copied into a project's source tree rather than installed as a shared package.
  • Vtable: a table of function pointers used to dispatch methods in object-oriented code.
  • Wrap: when a value too large for its type rolls over to a smaller value, like an odometer.

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.