Browse Source

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.
Karol Kosek 4 years ago
parent
commit
01e1e2c2c5
1 changed files with 5 additions and 5 deletions
  1. 5 5
      Userland/Libraries/LibAudio/FlacLoader.cpp

+ 5 - 5
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