cli/caff.c, cli/aiff.c: reject non-finite sample rate before int cast#256
Merged
Merged
Conversation
A NaN sample rate slips past the <= 0 / > max range check and reaches (int) floor (rate + 0.5), which is undefined. Require a finite in-range value instead.
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.
UBSan, clang -fsanitize=undefined, running the file-format parsers on crafted input:
ParseCaffHeaderConfig and ParseAiffHeaderConfig gate the sample rate with
rate <= 0.0 || rate > 16777215.0, then convert it with(int) floor (rate + 0.5). Every comparison against NaN is false, so a NaN rate walks straight past the gate into the cast, which is undefined.For CAF the rate is an IEEE double copied verbatim from the 'desc' chunk, so the NaN is supplied directly. For AIFF it is the 80-bit extended value in COMM; a zero mantissa with a maximal exponent gives 0 * inf = NaN. Both are reachable from
wavpack file.caf/wavpack file.aif, which the fuzzer does not exercise.Requiring a finite in-range value rejects the file before the cast. For finite rates the new test is the same range, so valid input behaves exactly as before.