Commit 6f7ec60c authored by Erik de Castro Lopo's avatar Erik de Castro Lopo
Browse files

stream_encoder.c : Fix an arithmetic overflow in the RICE2 partitioner.

For a specific 24 bit WAV file provided by Leigh Dyer

encoding with compression level 7 was generating a file a couple of
orders of magintude larger than the original.

Debugging showed that variable abs_residual_partition_sum (a FLAC__uint32)
in function precompute_partition_info_sums_() was suffering from an
arithmetic overflowing on some 24 bit input files although this value
overflowing did not always cause larger output files.

Since the value abs_residual_partition_sum is eventually stored in an
array of FLAC__uint64, it makes sense to make abs_residual_partition_sum
a FLAC__uint64 anyway.

Debugging this problem was made easier by use of the Clang compiler's
-fsanitize=integer option.
parent cf0277bd
......@@ -3784,7 +3784,7 @@ void precompute_partition_info_sums_(
/* slightly pessimistic but still catches all common cases */
/* WATCHOUT: "+ bps" is an assumption that the average residual magnitude will not be more than "bps" bits */
if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
FLAC__uint32 abs_residual_partition_sum;
FLAC__uint64 abs_residual_partition_sum;
for(partition = residual_sample = 0; partition < partitions; partition++) {
end += default_partition_samples;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment