mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
stream_encoder.c : Fix an arithmetic overflow in the RICE2 partitioner.
For a specific 24 bit WAV file provided by Leigh Dyer
http://lists.xiph.org/pipermail/flac-dev/2013-July/004284.html
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.
This commit is contained in:
@@ -3784,7 +3784,7 @@ void precompute_partition_info_sums_(
|
|||||||
/* slightly pessimistic but still catches all common cases */
|
/* 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 */
|
/* 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) {
|
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++) {
|
for(partition = residual_sample = 0; partition < partitions; partition++) {
|
||||||
end += default_partition_samples;
|
end += default_partition_samples;
|
||||||
|
|||||||
Reference in New Issue
Block a user