From 95988b44a0f28dab0cc9cf7876836fb618e6eb58 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 17 Jan 2021 00:51:41 +0100 Subject: [PATCH] LibGfx: Let PNGLoader handle failed chunk decoding gracefully decode_png_chunks() is not handling "critical" chunks, unlike decode_png_size() for example. When we encounter a chunk decoding failure, e.g. because not enough bytes were left to read, just continue with decoding the bitmap - which will fail on its own, if we're missing some required chunk(s). Fixes #4984. --- Userland/Libraries/LibGfx/PNGLoader.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGfx/PNGLoader.cpp b/Userland/Libraries/LibGfx/PNGLoader.cpp index 48405f8bea..547e85b382 100644 --- a/Userland/Libraries/LibGfx/PNGLoader.cpp +++ b/Userland/Libraries/LibGfx/PNGLoader.cpp @@ -592,8 +592,9 @@ static bool decode_png_chunks(PNGLoadingContext& context) Streamer streamer(data_ptr, data_remaining); while (!streamer.at_end()) { if (!process_chunk(streamer, context)) { - context.state = PNGLoadingContext::State::Error; - return false; + // Ignore failed chunk and just consider chunk decoding being done. + // decode_png_bitmap() will check whether we got all required ones anyway. + break; } }