libFLAC/stream_decoder.c: Fix divide by zero error in FLAC__stream_decoder_seek_absolute

This commit is contained in:
Neelkamal Semwal
2020-10-21 18:30:47 +05:30
committed by Erik de Castro Lopo
parent 159cd6c41a
commit d7b33142ec

View File

@@ -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;