From 2878ad681efcbff0a18be4856f25124c46d281c9 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Tue, 26 Jul 2022 20:27:20 +0200 Subject: [PATCH] LibAudio: Read FLAC Metadata blocks larger than the buffer size Out of 40/63 failed tests, this change reduces the number down to four. :^) See: #14683 --- Userland/Libraries/LibAudio/FlacLoader.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp index a5def7b03c..d8e4c2135f 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.cpp +++ b/Userland/Libraries/LibAudio/FlacLoader.cpp @@ -181,8 +181,14 @@ ErrorOr FlacLoaderPlugin::next_meta_block(Big auto block_data_result = ByteBuffer::create_uninitialized(block_length); FLAC_VERIFY(!block_data_result.is_error(), LoaderError::Category::IO, "Out of memory"); auto block_data = block_data_result.release_value(); - // Reads exactly the bytes necessary into the Bytes container - LOADER_TRY(bit_input.read(block_data)); + + // Blocks might exceed our buffer size. + auto bytes_left_to_read = block_data.bytes(); + while (bytes_left_to_read.size()) { + auto read_bytes = LOADER_TRY(bit_input.read(bytes_left_to_read)); + bytes_left_to_read = bytes_left_to_read.slice(read_bytes.size()); + } + m_data_start_location += block_length; return FlacRawMetadataBlock { is_last_block,