[libpng16] Control ADLER32 checking with new PNG_IGNORE_ADLER32 option.
diff --git a/ANNOUNCE b/ANNOUNCE
index 4e975ff..8a8dee0 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,4 +1,4 @@
-Libpng 1.6.27beta02 - November 8, 2016
+Libpng 1.6.27beta02 - December 26, 2016
 
 This is not intended to be a public release.  It will be replaced
 within a few weeks by a public version or by another test version.
@@ -31,8 +31,8 @@
     entire PNG image instead of rejecting just the iCCP chunk with a warning,
     if built with zlib-1.2.8.1.
 
-Version 1.6.27beta02 [November 8, 2016]
-  Revert ADLER32 error handling in pngrutil.c and pngpread.c.
+Version 1.6.27beta02 [December 26, 2016]
+  Control ADLER32 checking with new PNG_IGNORE_ADLER32 option.
 
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 (subscription required; visit
diff --git a/CHANGES b/CHANGES
index 41897f6..0feb7a7 100644
--- a/CHANGES
+++ b/CHANGES
@@ -5760,8 +5760,8 @@
     entire PNG image instead of rejecting just the iCCP chunk with a warning,
     if built with zlib-1.2.8.1.
 
-Version 1.6.27beta02 [November 8, 2016]
-  Revert ADLER32 error handling in pngrutil.c and pngpread.c.
+Version 1.6.27beta02 [December 26, 2016]
+  Control ADLER32 checking with new PNG_IGNORE_ADLER32 option.
 
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 (subscription required; visit
diff --git a/png.c b/png.c
index 71d3fb2..1931a49 100644
--- a/png.c
+++ b/png.c
@@ -1,7 +1,7 @@
 
 /* png.c - location for general purpose libpng functions
  *
- * Last changed in libpng 1.6.26 [October 20, 2016]
+ * Last changed in libpng 1.6.27 [(PENDING RELEASE)]
  * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@@ -775,14 +775,14 @@
 #else
 #  ifdef __STDC__
    return PNG_STRING_NEWLINE \
-      "libpng version 1.6.27beta02 - November 2, 2016" PNG_STRING_NEWLINE \
+      "libpng version 1.6.27beta02 - December 26, 2016" PNG_STRING_NEWLINE \
       "Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson" \
       PNG_STRING_NEWLINE \
       "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
       "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
       PNG_STRING_NEWLINE;
 #  else
-   return "libpng version 1.6.27beta02 - November 2, 2016\
+   return "libpng version 1.6.27beta02 - December 26, 2016\
       Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\
       Copyright (c) 1996-1997 Andreas Dilger\
       Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
diff --git a/png.h b/png.h
index 88cf094..4b49aa0 100644
--- a/png.h
+++ b/png.h
@@ -1,7 +1,7 @@
 
 /* png.h - header file for PNG reference library
  *
- * libpng version 1.6.27beta02, November 2, 2016
+ * libpng version 1.6.27beta02, December 26, 2016
  *
  * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -12,7 +12,7 @@
  * Authors and maintainers:
  *   libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
  *   libpng versions 0.89, June 1996, through 0.96, May 1997: Andreas Dilger
- *   libpng versions 0.97, January 1998, through 1.6.27beta02, November 2, 2016:
+ *   libpng versions 0.97, January 1998, through 1.6.27beta02, December 26, 2016:
  *     Glenn Randers-Pehrson.
  *   See also "Contributing Authors", below.
  */
@@ -29,7 +29,7 @@
  * files that are distributed with libpng have other copyright owners and
  * are released under other open source licenses.
  *
- * libpng versions 1.0.7, July 1, 2000 through 1.6.27beta02, November 2, 2016 are
+ * libpng versions 1.0.7, July 1, 2000 through 1.6.27beta02, December 26, 2016 are
  * Copyright (c) 2000-2002, 2004, 2006-2016 Glenn Randers-Pehrson, are
  * derived from libpng-1.0.6, and are distributed according to the same
  * disclaimer and license as libpng-1.0.6 with the following individuals
@@ -246,7 +246,7 @@
  * Y2K compliance in libpng:
  * =========================
  *
- *    November 2, 2016
+ *    December 26, 2016
  *
  *    Since the PNG Development group is an ad-hoc body, we can't make
  *    an official declaration.
@@ -315,7 +315,7 @@
 
 /* Version information for png.h - this should match the version in png.c */
 #define PNG_LIBPNG_VER_STRING "1.6.27beta02"
-#define PNG_HEADER_VERSION_STRING " libpng version 1.6.27beta02 - November 2, 2016\n"
+#define PNG_HEADER_VERSION_STRING " libpng version 1.6.27beta02 - December 26, 2016\n"
 
 #define PNG_LIBPNG_VER_SONUM   16
 #define PNG_LIBPNG_VER_DLLNUM  16
@@ -3230,7 +3230,8 @@
 #ifdef PNG_MIPS_MSA_API_SUPPORTED
 #  define PNG_MIPS_MSA   6 /* HARDWARE: MIPS Msa SIMD instructions supported */
 #endif
-#define PNG_OPTION_NEXT  8 /* Next option - numbers must be even */
+#define PNG_IGNORE_ADLER32 8
+#define PNG_OPTION_NEXT  10 /* Next option - numbers must be even */
 
 /* Return values: NOTE: there are four values and 'off' is *not* zero */
 #define PNG_OPTION_UNSET   0 /* Unset - defaults to off */
diff --git a/pngrutil.c b/pngrutil.c
index b385d6e..9313e4b 100644
--- a/pngrutil.c
+++ b/pngrutil.c
@@ -418,10 +418,10 @@
             png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED;
       }
 
-#if ZLIB_VERNUM >= 0x1281
-      /* Turn off validation of the ADLER32 checksum in IDAT chunks */
-      if ((png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) != 0 &&
-          png_ptr->zowner == png_IDAT)
+#if ZLIB_VERNUM >= 0x1281 && \
+   defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_IGNORE_ADLER32)
+      if (((png_ptr->options >> PNG_IGNORE_ADLER32) & 3) == PNG_OPTION_ON)
+         /* Turn off validation of the ADLER32 checksum in IDAT chunks */
          ret = inflateValidate(&png_ptr->zstream, 0);
 #endif
 
@@ -717,7 +717,7 @@
                    * the extra space may otherwise be used as a Trojan Horse.
                    */
                   if (ret == Z_STREAM_END &&
-                     chunklength - prefix_size != lzsize)
+                      chunklength - prefix_size != lzsize)
                      png_chunk_benign_error(png_ptr, "extra compressed data");
                }
 
@@ -827,7 +827,7 @@
       return Z_STREAM_ERROR;
    }
 }
-#endif
+#endif /* READ_iCCP */
 
 /* Read and check the IDHR chunk */
 
@@ -4108,7 +4108,9 @@
          png_zstream_error(png_ptr, ret);
 
          if (output != NULL)
-            png_chunk_error(png_ptr, png_ptr->zstream.msg);
+         {
+               png_chunk_error(png_ptr, png_ptr->zstream.msg);
+         }
 
          else /* checking */
          {
diff --git a/pngtest.c b/pngtest.c
index 7d3e91b..eaf2798 100644
--- a/pngtest.c
+++ b/pngtest.c
@@ -986,9 +986,14 @@
       /* Allow application (pngtest) errors and warnings to pass */
       png_set_benign_errors(read_ptr, 1);
 
-      /* Turn off CRC and ADLER32 checking while reading */
+      /* Turn off CRC checking while reading */
       png_set_crc_action(read_ptr, PNG_CRC_QUIET_USE, PNG_CRC_QUIET_USE);
 
+#ifdef PNG_IGNORE_ADLER32_SUPPORTED
+      /* Turn off ADLER32 checking while reading */
+      png_set_option(read_ptr, PNG_IGNORE_ADLER32, PNG_OPTION_ON);
+#endif
+
 # ifdef PNG_WRITE_SUPPORTED
       png_set_benign_errors(write_ptr, 1);
 # endif