fix left shift of negative width in legacy get_word3/get_old_word1#245
Open
aizu-m wants to merge 1 commit into
Open
fix left shift of negative width in legacy get_word3/get_old_word1#245aizu-m wants to merge 1 commit into
aizu-m wants to merge 1 commit into
Conversation
get_word3 and get_old_word1 update their running bit-width averages with value << 3 before the width is range checked, so a crafted version-3 stream can shift a negative dbits/k_value, which is undefined. Cast to uint32_t before the shift, as the min_value/max_value shifts in unpack_samples3 already do.
Owner
|
Thanks for this, but I think a cleaner fix would be to replace the left-shift of 3 with a multiply by 8. It's not ugly like the cast and optimizing compilers are going to generate the same code anyway. What do you think? |
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.
Turned this up building --enable-legacy under -fsanitize=undefined and decoding mutated version-3 files.
UBSan reports "left shift of negative value -40" at the get_word3 update on a crafted lossy mono file. The shifted result is only consumed on the error path, so output for valid files is unchanged. Cast the operand to uint32_t before the shift, matching the min_value/max_value shifts already in unpack_samples3. Added a regression file under fuzzing/regression/.