瀏覽代碼

LibGfx/PNG: Reject files that doesn't start with a IHDr chunk

Lucas CHOLLET 2 年之前
父節點
當前提交
a173275afa
共有 1 個文件被更改,包括 4 次插入0 次删除
  1. 4 0
      Userland/Libraries/LibGfx/ImageFormats/PNGLoader.cpp

+ 4 - 0
Userland/Libraries/LibGfx/ImageFormats/PNGLoader.cpp

@@ -1212,6 +1212,10 @@ static ErrorOr<void> process_chunk(Streamer& streamer, PNGLoadingContext& contex
 
 
     if (chunk_type == "IHDR"sv)
     if (chunk_type == "IHDR"sv)
         return process_IHDR(chunk_data, context);
         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)
     if (chunk_type == "IDAT"sv)
         return process_IDAT(chunk_data, context);
         return process_IDAT(chunk_data, context);
     if (chunk_type == "PLTE"sv)
     if (chunk_type == "PLTE"sv)