Skip to content

dr_wav: Validate ADPCM block header size against data chunk size#299

Closed
timblechmann wants to merge 1 commit intomackron:masterfrom
timblechmann:fix/integer-underflow
Closed

dr_wav: Validate ADPCM block header size against data chunk size#299
timblechmann wants to merge 1 commit intomackron:masterfrom
timblechmann:fix/integer-underflow

Conversation

@timblechmann
Copy link
Copy Markdown

Add a guard to ensure dataChunkSize is not smaller than the calculated total block header size (blockCount * (6 * fmt.channels)) when parsing ADPCM data. If the header size exceeds the data chunk size, the file is invalid, so metadata is freed and initialization fails early.

This prevents underflow in the PCM frame count calculation and avoids processing malformed or truncated WAV files.


this file would end up with an invalid totalPCMFrameCount:
notification.wav

Add a guard to ensure `dataChunkSize` is not smaller than the calculated
total block header size (`blockCount * (6 * fmt.channels)`) when parsing
ADPCM data. If the header size exceeds the data chunk size, the file is
invalid, so metadata is freed and initialization fails early.

This prevents underflow in the PCM frame count calculation and avoids
processing malformed or truncated WAV files.
@mackron
Copy link
Copy Markdown
Owner

mackron commented Mar 8, 2026

Thanks. Just acknowledging that I've seen this. Will report back when I get a chance to properly review it.

mackron added a commit that referenced this pull request Apr 24, 2026
@mackron
Copy link
Copy Markdown
Owner

mackron commented Apr 24, 2026

I've fixed this one manually. Your change was doing the check before totalBlockHeaderSizeInBytes had actually been assigned a value. Also, you were addressing the DR_WAVE_FORMAT_ADPCM case, but the same fix was also needed for the DR_WAVE_FORMAT_DVI_ADPCM.

Thanks for the report!

@mackron mackron closed this Apr 24, 2026
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.

2 participants