From a173275afa9864463e7aa4d748960a31cd7b87aa Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Mon, 17 Jul 2023 00:22:11 -0400 Subject: [PATCH] LibGfx/PNG: Reject files that doesn't start with a IHDr chunk --- Userland/Libraries/LibGfx/ImageFormats/PNGLoader.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Userland/Libraries/LibGfx/ImageFormats/PNGLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/PNGLoader.cpp index 998e0673ab..07bc7df07d 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/PNGLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/PNGLoader.cpp @@ -1212,6 +1212,10 @@ static ErrorOr process_chunk(Streamer& streamer, PNGLoadingContext& contex if (chunk_type == "IHDR"sv) return process_IHDR(chunk_data, context); + + if (context.state < PNGLoadingContext::IHDRDecoded) + return Error::from_string_literal("IHDR is not the first chunk of the file"); + if (chunk_type == "IDAT"sv) return process_IDAT(chunk_data, context); if (chunk_type == "PLTE"sv)