From 01e1e2c2c5f8eceb322682a7122796e4e86d5bc6 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Thu, 22 Jul 2021 15:34:24 +0200 Subject: [PATCH] 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. --- Userland/Libraries/LibAudio/FlacLoader.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp index 639ea05231..2cb2898111 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.cpp +++ b/Userland/Libraries/LibAudio/FlacLoader.cpp @@ -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