LibAudio: Read custom block sizes and sample rates as big endian

This fixes stucking in a loop at the end of the file, as
(a) custom block sizes are usually placed there, as the remaining
size might not be simply calculated as a power of two, and
(b) the number of bytes to read was incorrect (the program said
the block size was 32525, where flac -a said it's actually 3200).

Unfortunately, I couldn't trigger the bug for the sample rates,
so it may be not true, but I'd doubt it, giving the fact that flac
almost everywhere uses big endian numbers.
This commit is contained in:
Karol Kosek 2021-07-22 15:34:24 +02:00 committed by Andreas Kling
commit 01e1e2c2c5
Notes: sideshowbarker 2024-07-19 17:23:37 +09:00

View file

@ -296,17 +296,17 @@ void FlacLoaderPlugin::next_frame()
// Conditional header variables
if (sample_count == FLAC_BLOCKSIZE_AT_END_OF_HEADER_8) {
sample_count = bit_stream.read_bits(8) + 1;
sample_count = bit_stream.read_bits_big_endian(8) + 1;
} else if (sample_count == FLAC_BLOCKSIZE_AT_END_OF_HEADER_16) {
sample_count = bit_stream.read_bits(16) + 1;
sample_count = bit_stream.read_bits_big_endian(16) + 1;
}
if (frame_sample_rate == FLAC_SAMPLERATE_AT_END_OF_HEADER_8) {
frame_sample_rate = bit_stream.read_bits(8) * 1000;
frame_sample_rate = bit_stream.read_bits_big_endian(8) * 1000;
} else if (frame_sample_rate == FLAC_SAMPLERATE_AT_END_OF_HEADER_16) {
frame_sample_rate = bit_stream.read_bits(16);
frame_sample_rate = bit_stream.read_bits_big_endian(16);
} else if (frame_sample_rate == FLAC_SAMPLERATE_AT_END_OF_HEADER_16X10) {
frame_sample_rate = bit_stream.read_bits(16) * 10;
frame_sample_rate = bit_stream.read_bits_big_endian(16) * 10;
}
// TODO: check header checksum, see above