From 26b28d50a95dd2f943824bf9c47f7325e60b15e3 Mon Sep 17 00:00:00 2001
From: Glenn Randers-Pehrson <glennrp@gmail.com>
Date: Wed, 2 Aug 2017 15:52:12 -0400
Subject: [PATCH] Added "-define png:ignore-crc" option to PNG decoder

---
 ChangeLog    |  3 +++
 coders/png.c | 13 +++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 96803ec81..d737da833 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,9 @@
     https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=32418).
   * Fix improper use of NULL in the JNG decoder (CVE-2017-11750, Reference
     https://github.com/ImageMagick/ImageMagick/issues/632).
+  * Added "-define png:ignore-crc" option to PNG decoder. When you know
+    your image has no CRC or ADLER32 errors, this can speed up decoding.
+    It is also helpful in debugging bug reports from "fuzzers".
 
 2017-07-29  7.0.6-5 Cristy  <quetzlzacatenango@image...>
   * Off by one error for gradient coder (reference
diff --git a/coders/png.c b/coders/png.c
index e8e264f0e..f9bea7f4c 100644
--- a/coders/png.c
+++ b/coders/png.c
@@ -2428,6 +2428,19 @@ static Image *ReadOnePNGImage(MngInfo *mng_info,
     const char
       *value;
 
+    value=GetImageOption(image_info,"png:ignore-crc");
+    if (value != NULL)
+    {
+       /* Turn off CRC checking while reading */
+       png_set_crc_action(ping, PNG_CRC_QUIET_USE, PNG_CRC_QUIET_USE);
+#ifdef PNG_IGNORE_ADLER32
+       /* Turn off ADLER32 checking while reading */
+       png_set_option(ping, PNG_IGNORE_ADLER32, PNG_OPTION_ON);
+#endif
+     }
+
+    ping_preserve_iCCP=MagickTrue;
+
     value=GetImageOption(image_info,"profile:skip");
 
     if (IsOptionMember("ICC",value) == MagickFalse)
-- 
2.40.0