From d7b33142ecb4e64b7eaf54564d6ad6e7f20a6c5d Mon Sep 17 00:00:00 2001 From: Neelkamal Semwal Date: Wed, 21 Oct 2020 18:30:47 +0530 Subject: libFLAC/stream_decoder.c: Fix divide by zero error in FLAC__stream_decoder_seek_absolute --- src/libFLAC/stream_decoder.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libFLAC/stream_decoder.c b/src/libFLAC/stream_decoder.c index aa63b2ca..3ca7f44f 100644 --- a/src/libFLAC/stream_decoder.c +++ b/src/libFLAC/stream_decoder.c @@ -3130,8 +3130,10 @@ 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 ratio = (1<<16) / (upper_bound_sample - lower_bound_sample); + pos = (FLAC__int64)lower_bound + (FLAC__int64)((((target_sample - lower_bound_sample)>>8) * ((upper_bound - lower_bound)>>8) * ratio)) - approx_bytes_per_frame; + } #endif if(pos >= (FLAC__int64)upper_bound) pos = (FLAC__int64)upper_bound - 1; -- cgit v1.2.1