From 8d907b653591db834b7f33cc73adea1f41423f0a Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Mon, 17 Jul 2023 00:18:42 -0400 Subject: [PATCH] LibGfx/PNG: Don't use a loop to read chunks in `decode_png_ihdr()` This chunk is the first one, so we can remove that loop. --- .../Libraries/LibGfx/ImageFormats/PNGLoader.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/PNGLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/PNGLoader.cpp index 85dc19f9b9..998e0673ab 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/PNGLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/PNGLoader.cpp @@ -614,14 +614,15 @@ static ErrorOr decode_png_ihdr(PNGLoadingContext& context) size_t data_remaining = context.data_size - (context.data_current_ptr - context.data); Streamer streamer(context.data_current_ptr, data_remaining); - while (!streamer.at_end() && !context.has_seen_iend) { - TRY(process_chunk(streamer, context)); - context.data_current_ptr = streamer.current_data_ptr(); + // https://www.w3.org/TR/png/#11IHDR + // The IHDR chunk shall be the first chunk in the PNG datastream. + TRY(process_chunk(streamer, context)); - if (context.state == PNGLoadingContext::State::IHDRDecoded) - return {}; - } + context.data_current_ptr = streamer.current_data_ptr(); + + VERIFY(context.state == PNGLoadingContext::State::IHDRDecoded); + return {}; } static bool decode_png_image_data_chunk(PNGLoadingContext& context)