소스 검색

LibGfx/PNG: Make invalid sRGB chunk size non-fatal

https://www.haiku-os.org/images/bg-page.png has a size of 0 for
example.

Just ignoring the chunk instead of assuming that the image is sRGB
and has Perceptual rendering intent matches what libpng does
(cf `png_handle_sRGB()`), so let's do that too.

(All other chunk handlers are still strict about size.)
Nico Weber 2 년 전
부모
커밋
f7f9f1f47f
1개의 변경된 파일5개의 추가작업 그리고 2개의 파일을 삭제
  1. 5 2
      Userland/Libraries/LibGfx/ImageFormats/PNGLoader.cpp

+ 5 - 2
Userland/Libraries/LibGfx/ImageFormats/PNGLoader.cpp

@@ -1104,8 +1104,11 @@ static ErrorOr<void> process_gAMA(ReadonlyBytes data, PNGLoadingContext& context
 static ErrorOr<void> process_sRGB(ReadonlyBytes data, PNGLoadingContext& context)
 {
     // https://www.w3.org/TR/png/#srgb-standard-colour-space
-    if (data.size() != 1)
-        return Error::from_string_literal("sRGB chunk has an abnormal size");
+    if (data.size() != 1) {
+        // Invalid per spec, but (rarely) happens in the wild. Log and ignore.
+        warnln("warning: PNG sRGB chunk has an abnormal size; ignoring");
+        return {};
+    }
 
     u8 rendering_intent = data[0];
     if (rendering_intent > 3)