From 661b2d394d600a7dc334691a05dce7a49699254f Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 1 Jun 2023 09:09:24 -0400 Subject: WebP/Lossy: Clamp negative quantization indices to zero The spec doesn't talk about this happening in the text, but `dequant_init()` in 20.4 stores `q` in an int and clamps that to 0 later. --- Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Userland') diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp index 811620fdbd..fe4c0a726f 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp @@ -621,7 +621,7 @@ i16 dequantize_value(i16 value, bool is_dc, QuantizationIndices const& quantizat y_ac_base = segmentation.quantizer_update_value[segment_id]; } - u8 dequantization_index; + int dequantization_index; if (index.is_y2()) dequantization_index = y_ac_base + (is_dc ? quantization_indices.y2_dc_delta : quantization_indices.y2_ac_delta); else if (index.is_u() || index.is_v()) @@ -631,9 +631,9 @@ i16 dequantize_value(i16 value, bool is_dc, QuantizationIndices const& quantizat // clamp index if ((index.is_u() || index.is_v()) && is_dc) - dequantization_index = min(dequantization_index, 117); + dequantization_index = clamp(dequantization_index, 0, 117); else - dequantization_index = min(dequantization_index, 127); + dequantization_index = clamp(dequantization_index, 0, 127); // "the multiplies are computed and stored using 16-bit signed integers." i16 dequantization_factor; -- cgit v1.2.3