dr_wav: Fix two integer overflows found by OSS-Fuzz. - #332
Closed
timblechmann wants to merge 1 commit into
Closed
Conversation
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>
Contributor
Author
|
reduced test cases: |
Owner
|
This should be fixed in the master branch. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In drwav_init__internal()'s AIFF COMM chunk handling, blockAlign was computed as
fmt.channels * fmt.bitsPerSample / 8where 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.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.