Skip to content
Memory corruption Advisory Advanced CVE-2021-40426

Sound Exchange libsox sphere.c start_read() heap-based buffer overflow vulnerability

A heap-based buffer overflow exists in libsox's sphere.c start_read() due to an off-by-one in lsx_reads and incorrect size accounting, allowing a crafted .sph file to overwrite heap memory. An attacker can provide a malicious file to trigger the overflow, potentially leading to code execution.

Lilith >_> Follow

Originally disclosed on Cisco Talos

Critical 10.0 View original

A heap-based buffer overflow vulnerability exists in the sphere.c startread() functionality of Sound Exchange libsox 14.4.2 and master commit 42b3557e. A specially-crafted file can lead to a heap buffer overflow.

Lilith >_>, on Cisco Talos

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.

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 combination of an off-by-one in lsx_reads (which writes len+1 bytes) and the subsequent subtraction of strlen(buf)+1 from header_size causes an integer underflow, leading to a heap buffer overflow on the next read.

Impact

A crafted file could cause a heap buffer overflow, potentially leading to code execution or denial of service.

What the attacker needed

Victim opens a malicious .sph file

How it was found

  1. Craft a file starting with the magic bytes 'NIST_1A' followed by an 8-byte header size value.
  2. Set the header size such that after subtracting 16, the remaining size is small (e.g., 22).
  3. Include header lines that do not contain 'end_head', causing the loop to continue.
  4. Provide a long line that overflows the allocated buffer when read by lsx_reads.
  5. Follow with an 'end_head' line to allow processing to continue.

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.

This is a memory corruption bug in an audio library. When the library reads a specially crafted file, it writes more data into a memory buffer than the buffer can hold, which can crash the program or let an attacker run their own code.

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 Lilith >_>

View all

148 more disclosed reports, best first.

More from Cisco Talos

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.