diff options
author | Nico Weber <thakis@chromium.org> | 2023-03-31 10:38:34 -0400 |
---|---|---|
committer | Jelle Raaijmakers <jelle@gmta.nl> | 2023-04-05 13:24:00 +0200 |
commit | 830fd0d5b2327868094251c5fc7c52b90d4b8ed2 (patch) | |
tree | de949c5c482798ce1fa4ae3624b2ac4a013000ce /Userland | |
parent | a65b0cbe4a487b225bfb23182ed65f292263b516 (diff) | |
download | serenity-830fd0d5b2327868094251c5fc7c52b90d4b8ed2.zip |
LibGfx: Read webp lossless header using LittleEndianInputBitStream
No behavior change. Covered by existing webp decoder tests :^)
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp index 3106e66088..d3a6dcce82 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp @@ -4,9 +4,11 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <AK/BitStream.h> #include <AK/Debug.h> #include <AK/Endian.h> #include <AK/Format.h> +#include <AK/MemoryStream.h> #include <AK/Vector.h> #include <LibGfx/ImageFormats/WebPLoader.h> @@ -271,16 +273,19 @@ static ErrorOr<VP8LHeader> decode_webp_chunk_VP8L_header(WebPLoadingContext& con if (vp8l_chunk.data.size() < 5) return context.error("WebPImageDecoderPlugin: VP8L chunk too small"); - u8 const* data = vp8l_chunk.data.data(); - u8 signature = data[0]; + FixedMemoryStream memory_stream { vp8l_chunk.data.trim(5) }; + LittleEndianInputBitStream bit_stream { MaybeOwned<Stream>(memory_stream) }; + + u8 signature = TRY(bit_stream.read_bits(8)); if (signature != 0x2f) return context.error("WebPImageDecoderPlugin: VP8L chunk invalid signature"); // 14 bits width-1, 14 bits height-1, 1 bit alpha hint, 3 bit version_number. - u16 width = (data[1] | ((data[2] & 0x3f) << 8)) + 1; - u16 height = ((data[2] >> 6) | (data[3] << 2) | ((data[4] & 0xf) << 12)) + 1; - bool is_alpha_used = (data[4] & 0x10) != 0; - u8 version_number = (data[4] & 0xe0) >> 5; + u16 width = TRY(bit_stream.read_bits(14)) + 1; + u16 height = TRY(bit_stream.read_bits(14)) + 1; + bool is_alpha_used = TRY(bit_stream.read_bits(1)) != 0; + u8 version_number = TRY(bit_stream.read_bits(3)); + VERIFY(bit_stream.is_eof()); dbgln_if(WEBP_DEBUG, "width {}, height {}, is_alpha_used {}, version_number {}", width, height, is_alpha_used, version_number); |