Skip to content

Fix unsigned integer underflow in mp3dec_ex_read_frame leading to heap buffer overflow#148

Open
izumi-hyun wants to merge 1 commit into
lieff:masterfrom
izumi-hyun:master
Open

Fix unsigned integer underflow in mp3dec_ex_read_frame leading to heap buffer overflow#148
izumi-hyun wants to merge 1 commit into
lieff:masterfrom
izumi-hyun:master

Conversation

@izumi-hyun

@izumi-hyun izumi-hyun commented May 24, 2026

Copy link
Copy Markdown

Description

This PR fixes an unsigned integer underflow condition in mp3dec_ex_read_frame within minimp3_ex.h.

During analysis of a malformed MP3 file, I observed a state where:

end_offset = 192
dec->offset = 274

The remaining buffer size is calculated as:

uint64_t buf_size = end_offset - dec->offset;

Because no validation is performed before the subtraction, this results in an unsigned integer underflow and produces an unexpectedly large buf_size value.

The underflow condition was observed together with a reproducible AddressSanitizer-reported heap out-of-bounds read during frame decoding.

Root Cause

uint64_t buf_size = end_offset - dec->offset;

If dec->offset > end_offset, the subtraction underflows.

Proposed Fix

if (dec->offset >= end_offset)
    return 0;

This prevents the underflow condition before the buffer size calculation.

Impact

This fix prevents malformed input from triggering the underflow condition and avoids passing an invalid buffer range into the decoding path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant