Skip to content

dr_wav: Fix two integer overflows found by OSS-Fuzz. - #332

Closed
timblechmann wants to merge 1 commit into
mackron:masterfrom
timblechmann:fixes/wav-fix-integer-overflows
Closed

dr_wav: Fix two integer overflows found by OSS-Fuzz.#332
timblechmann wants to merge 1 commit into
mackron:masterfrom
timblechmann:fixes/wav-fix-integer-overflows

Conversation

@timblechmann

Copy link
Copy Markdown
Contributor
  1. In drwav_init__internal()'s AIFF COMM chunk handling, blockAlign was computed as fmt.channels * fmt.bitsPerSample / 8 where both operands are drwav_uint16 read directly from the file. Promoted to int, this multiplication can overflow (e.g. 65312 * 65312) when a crafted file declares implausible channel/bit-depth values. Cast to drwav_uint32 before multiplying to avoid the signed overflow.

  2. drwav_f32_to_s16() and drwav_f64_to_s16() clamp each sample into [-1, 1] before scaling and truncating to an int, but comparisons against NaN are always false, so a NaN sample (e.g. from a corrupted IEEE float WAV) passes through the clamp unchanged and is then cast to int, which is undefined behaviour. Explicitly replace NaN samples with 0 before clamping.

Found by OSS-Fuzz.

1. In drwav_init__internal()'s AIFF COMM chunk handling, blockAlign
   was computed as `fmt.channels * fmt.bitsPerSample / 8` where both
   operands are drwav_uint16 read directly from the file. Promoted to
   int, this multiplication can overflow (e.g. 65312 * 65312) when a
   crafted file declares implausible channel/bit-depth values. Cast to
   drwav_uint32 before multiplying to avoid the signed overflow.

2. drwav_f32_to_s16() and drwav_f64_to_s16() clamp each sample into
   [-1, 1] before scaling and truncating to an int, but comparisons
   against NaN are always false, so a NaN sample (e.g. from a
   corrupted IEEE float WAV) passes through the clamp unchanged and is
   then cast to int, which is undefined behaviour. Explicitly replace
   NaN samples with 0 before clamping.

Found by OSS-Fuzz.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@timblechmann

Copy link
Copy Markdown
Contributor Author

reduced test cases:
clusterfuzz-testcase-minimized-dr_wav_fuzzer-.tar.gz

mackron added a commit that referenced this pull request Aug 31, 2026
@mackron

mackron commented Aug 31, 2026

Copy link
Copy Markdown
Owner

This should be fixed in the master branch.

@mackron mackron closed this Aug 31, 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