From 2b61193b7190e652eca966e5231d55069b409965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Sat, 19 Aug 2023 20:31:07 +0200 Subject: [PATCH] LibAudio: Account for garbage shifts in several places in FLAC loader --- Userland/Libraries/LibAudio/FlacLoader.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp index b9d37d790e..4a2eb9459a 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.cpp +++ b/Userland/Libraries/LibAudio/FlacLoader.cpp @@ -806,7 +806,7 @@ ErrorOr FlacLoaderPlugin::decode_custom_lpc(Vector& deco // These considerations are not in the original FLAC spec, but have been added to the IETF standard: https://datatracker.ietf.org/doc/html/draft-ietf-cellar-flac-03#appendix-A.3 sample.saturating_add(Checked::saturating_mul(static_cast(coefficients[t]), static_cast(decoded[i - t - 1]))); } - decoded[i] += sample.value() >> lpc_shift; + decoded[i] += lpc_shift >= 0 ? (sample.value() >> lpc_shift) : (sample.value() << -lpc_shift); } return {}; @@ -945,8 +945,10 @@ ALWAYS_INLINE ErrorOr, LoaderError> FlacLoaderPlugin::decode_rice_pa // escape code for unencoded binary partition if (k == (1 << partition_type) - 1) { u8 unencoded_bps = TRY(bit_input.read_bits(5)); - for (size_t r = 0; r < residual_sample_count; ++r) { - rice_partition[r] = sign_extend(TRY(bit_input.read_bits(unencoded_bps)), unencoded_bps); + if (unencoded_bps != 0) { + for (size_t r = 0; r < residual_sample_count; ++r) { + rice_partition[r] = sign_extend(TRY(bit_input.read_bits(unencoded_bps)), unencoded_bps); + } } } else { for (size_t r = 0; r < residual_sample_count; ++r) {