diff options
author | Ray Essick <essick@google.com> | 2021-03-13 23:34:46 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-03-13 23:34:46 +0000 |
commit | 3210dfbb5e927ccd2292e21c0c905a6211eb28fc (patch) | |
tree | c3aac8fb6e6965362d6eb9b42fd49d29f72949a9 | |
parent | a5fb016488e30e487d65086a4d39bae50e3fc369 (diff) | |
parent | 5bd2e7aba12ba8891aa6ae9ae6f262aa6e74c5f5 (diff) | |
download | flac-3210dfbb5e927ccd2292e21c0c905a6211eb28fc.tar.gz |
Merge "libFLAC: Fix divide by zero error in FLAC__stream_decoder_seek_absolute"android-s-beta-2android-s-beta-1
-rw-r--r-- | src/libFLAC/stream_decoder.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/libFLAC/stream_decoder.c b/src/libFLAC/stream_decoder.c index 5928bbeb..67070177 100644 --- a/src/libFLAC/stream_decoder.c +++ b/src/libFLAC/stream_decoder.c @@ -3119,8 +3119,11 @@ FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 s /* a little less accurate: */ if(upper_bound - lower_bound < 0xffffffff) pos = (FLAC__int64)lower_bound + (FLAC__int64)(((target_sample - lower_bound_sample) * (upper_bound - lower_bound)) / (upper_bound_sample - lower_bound_sample)) - approx_bytes_per_frame; - else /* @@@ WATCHOUT, ~2TB limit */ - pos = (FLAC__int64)lower_bound + (FLAC__int64)((((target_sample - lower_bound_sample)>>8) * ((upper_bound - lower_bound)>>8)) / ((upper_bound_sample - lower_bound_sample)>>16)) - approx_bytes_per_frame; + else { /* @@@ WATCHOUT, ~2TB limit */ + FLAC__uint64 sample_range_16 = (upper_bound_sample - lower_bound_sample) >> 16; + if (sample_range_16 == 0) sample_range_16 = 1; // avoid divide by 0 + pos = (FLAC__int64)lower_bound + (FLAC__int64)(((target_sample - lower_bound_sample) >> 8) * ((upper_bound - lower_bound) >> 8) / sample_range_16) - approx_bytes_per_frame; + } #endif if(pos >= (FLAC__int64)upper_bound) pos = (FLAC__int64)upper_bound - 1; |