From 47d3245ea7ae6a73cdbeea5b0991498236bc31a4 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 31 May 2024 15:50:41 -0400 Subject: [PATCH] LibGfx/WebPWriter: Do not convert -inf to unsigned Else UBSan complains about the color indexing test in this PR. --- Userland/Libraries/LibGfx/ImageFormats/WebPWriterLossless.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPWriterLossless.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPWriterLossless.cpp index 7c5d8877c53..70fc0e9c5e9 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPWriterLossless.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPWriterLossless.cpp @@ -206,7 +206,7 @@ static ErrorOr write_normal_code_lengths(LittleEndianOutputBitStr // "int length_nbits = 2 + 2 * ReadBits(3); // int max_symbol = 2 + ReadBits(length_nbits);" // => length_nbits is at most 2 + 2*7 == 16 - unsigned needed_length_nbits = floor(log2(encoded_lengths_count - 2) + 1); + unsigned needed_length_nbits = encoded_lengths_count > 2 ? floor(log2(encoded_lengths_count - 2) + 1) : 2; VERIFY(needed_length_nbits <= 16); needed_length_nbits = ceil_div(needed_length_nbits, 2) * 2; TRY(bit_stream.write_bits((needed_length_nbits - 2) / 2, 3u));