[master] Imported from libpng-1.6.2.tar
diff --git a/ANNOUNCE b/ANNOUNCE
index cc2064e..37a4b49 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,5 +1,5 @@
 
-Libpng 1.6.1 - March 28, 2013
+Libpng 1.6.2 - April 25, 2013
 
 This is a public release of libpng, intended for use in production codes.
 
@@ -8,89 +8,37 @@
 Source files with LF line endings (for Unix/Linux) and with a
 "configure" script
 
-   libpng-1.6.1.tar.xz (LZMA-compressed, recommended)
-   libpng-1.6.1.tar.gz
+   libpng-1.6.2.tar.xz (LZMA-compressed, recommended)
+   libpng-1.6.2.tar.gz
 
 Source files with CRLF line endings (for Windows), without the
 "configure" script
 
-   lpng161.7z  (LZMA-compressed, recommended)
-   lpng161.zip
+   lpng162.7z  (LZMA-compressed, recommended)
+   lpng162.zip
 
 Other information:
 
-   libpng-1.6.1-README.txt
-   libpng-1.6.1-LICENSE.txt
+   libpng-1.6.2-README.txt
+   libpng-1.6.2-LICENSE.txt
 
-Changes since the last public release (1.6.0):
+Changes since the last public release (1.6.1):
 
-  Made symbol prefixing work with the ARM neon optimizations. Also allow
-    pngpriv.h to be included for preprocessor definitions only, so it can
-    be used in non-C/C++ files. Back ported from libpng 1.7.
-  Made sRGB check numbers consistent.
-  Ported libpng 1.5 options.awk/dfn file handling to 1.6, fixed one bug.
-  Removed cc -E workround, corrected png_get_palette_max API Tested on
-    SUN OS cc 5.9, which demonstrates the tokenization problem previously
-    avoided by using /lib/cpp.  Since all .dfn output is now protected in
-    double quotes unless it is to be macro substituted the fix should
-    work everywhere.
-  Enabled parallel tests - back ported from libpng-1.7.
-  scripts/pnglibconf.dfa formatting improvements back ported from libpng17.
-  Fixed a race condition in the creation of the build 'scripts' directory
-    while building with a parallel make.
-  Use approved/supported Android method to check for NEON, use Linux/POSIX
-    1003.1 API to check /proc/self/auxv avoiding buffer allocation and other
-    library calls (ported from libpng15).
-  Use parentheses more consistently in "#if defined(MACRO)" tests.
-  Folded long lines.
-  Reenabled code to allow zero length PLTE chunks for MNG.
-  Fixed ALIGNED_MEMORY support.
-  Allow run-time ARM NEON checking to be disabled. A new configure option:
-    --enable-arm-neon=always will stop the run-time checks. New checks
-    within arm/arm_init.c will cause the code not to be compiled unless
-    __ARM_NEON__ is set. This should make it fail safe (if someone asks
-    for it on then the build will fail if it can't be done.)
-  Updated the INSTALL document.
-  Revised INSTALL to recommend using CPPFLAGS instead of INCLUDES.
-  Revised scripts/makefile.freebsd to respect ZLIBLIB and ZLIBINC.
-  Revised scripts/dfn.awk to work with the buggy MSYS awk that has trouble
-    with CRLF line endings.
-  Avoid a possible memory leak in contrib/gregbook/readpng.c
-  Better documentation of unknown handling API interactions.
-  Corrected Android builds and corrected libpng.vers with symbol
-    prefixing This adds an API to set optimization options externally,
-    providing an alternative and general solution for the non-portable
-    run-time tests used by the ARM Neon code.  It also makes those tests
-    compile and link on Android.
-  The order of settings vs options in pnglibconf.h is reversed to allow
-    settings to depend on options and options can now set (or override) the
-    defaults for settings.
-  Corrected simplified API default gamma for color-mapped output, added
-    a flag to change default. In 1.6.0 when the simplified API was used
-    to produce color-mapped output from an input image with no gamma
-    information the gamma assumed for the input could be different from
-    that assumed for non-color-mapped output.  In particular 16-bit depth
-    input files were assumed to be sRGB encoded, whereas in the 'direct'
-    case they were assumed to have linear data.  This was an error.  The
-    fix makes the simplified API treat all input files the same way and
-    adds a new flag to the png_image::flags member to allow the
-    application/user to specify that 16-bit files contain sRGB data
-    rather than the default linear.
-  Fixed bugs in the pngpixel and makepng test programs.
-  Fixed CMakelists.txt to allow building a single variant of the library
-    (Claudio Bley):
-  Introduced a PNG_LIB_TARGETS variable that lists all activated library
-    targets.  It is an error if this variable ends up empty, ie. you have
-    to build at least one library variant.
-  Made the *_COPY targets only depend on library targets actually being build.
-  Use PNG_LIB_TARGETS to unify a code path.
-  Changed the CREATE_SYMLINK macro to expect the full path to a file as the
-    first argument. When symlinking the filename component of that path is
-    determined and used as the link target.
-  Use copy_if_different in the CREATE_SYMLINK macro.
-  Eliminated two warnings from the Intel C compiler. The warnings are
-    technically valid, although a reasonable treatment of division would
-    show it to be incorrect.
+  Updated documentation of 1.5.x to 1.6.x changes in iCCP chunk handling.
+  Fixed incorrect warning of excess deflate data. End condition - the
+    warning would be produced if the end of the deflate stream wasn't read
+    in the last row.  The warning is harmless.
+  Corrected the test on user transform changes on read. It was in the
+    png_set of the transform function, but that doesn't matter unless the
+    transform function changes the rowbuf size, and that is only valid if
+    transform_info is called.
+  Corrected a misplaced closing bracket in contrib/libtests/pngvalid.c
+    (Flavio Medeiros).
+  Corrected length written to uncompressed iTXt chunks (Samuli Suominen).
+  Added contrib/tools/fixitxt.c, to repair the erroneous iTXt chunk length
+    written by libpng-1.6.0 and 1.6.1.
+  Disallow storing sRGB information when the sRGB is not supported.
+  Merge pngtest.c with libpng-1.7.0
 
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 (subscription required; visit
diff --git a/CHANGES b/CHANGES
index 3825408..4d55fc0 100644
--- a/CHANGES
+++ b/CHANGES
@@ -4473,6 +4473,39 @@
 Version 1.6.1 [March 28, 2013]
   No changes.
 
+Version 1.6.2beta01 [April 14, 2013]
+  Updated documentation of 1.5.x to 1.6.x changes in iCCP chunk handling.
+  Fixed incorrect warning of excess deflate data. End condition - the
+    warning would be produced if the end of the deflate stream wasn't read
+    in the last row.  The warning is harmless.
+  Corrected the test on user transform changes on read. It was in the
+    png_set of the transform function, but that doesn't matter unless the
+    transform function changes the rowbuf size, and that is only valid if
+    transform_info is called.
+  Corrected a misplaced closing bracket in contrib/libtests/pngvalid.c
+    (Flavio Medeiros).
+  Corrected length written to uncompressed iTXt chunks (Samuli Suominen).
+
+Version 1.6.2rc01 [April 18, 2013]
+  Added contrib/tools/fixitxt.c, to repair the erroneous iTXt chunk length
+    written by libpng-1.6.0 and 1.6.1.
+  Disallow storing sRGB information when the sRGB is not supported.
+
+Version 1.6.2rc02 [April 18, 2013]
+  Merge pngtest.c with libpng-1.7.0
+
+Version 1.6.2rc03 [April 22, 2013]
+  Trivial spelling cleanup.
+
+Version 1.6.2rc04 and 1.6.2rc05 [omitted]
+
+Version 1.6.2rc06 [April 24, 2013]
+  Reverted to version 1.6.2rc03.  Recent changes to arm/neon support
+    have been ported to libpng-1.7.0beta09 and will reappear in version
+    1.6.3beta01.
+
+Version 1.6.2 [April 25, 2013]
+
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 (subscription required; visit
 https://lists.sourceforge.net/lists/listinfo/png-mng-implement
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1ebf0da..4104359 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,7 +35,7 @@
 
 set(PNGLIB_MAJOR 1)
 set(PNGLIB_MINOR 6)
-set(PNGLIB_RELEASE 1)
+set(PNGLIB_RELEASE 2)
 set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
 set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
 
@@ -271,7 +271,7 @@
 # SET UP LINKS
 if(PNG_SHARED)
   set_target_properties(${PNG_LIB_NAME} PROPERTIES
-#   VERSION 16.${PNGLIB_RELEASE}.1.6.1
+#   VERSION 16.${PNGLIB_RELEASE}.1.6.2
     VERSION 16.${PNGLIB_RELEASE}.0
     SOVERSION 16
     CLEAN_DIRECT_OUTPUT 1)
diff --git a/LICENSE b/LICENSE
index d86a7da..acb4e17 100644
--- a/LICENSE
+++ b/LICENSE
@@ -10,7 +10,7 @@
 
 This code is released under the libpng license.
 
-libpng versions 1.2.6, August 15, 2004, through 1.6.1, March 28, 2013, are
+libpng versions 1.2.6, August 15, 2004, through 1.6.2, April 25, 2013, are
 Copyright (c) 2004, 2006-2012 Glenn Randers-Pehrson, and are
 distributed according to the same disclaimer and license as libpng-1.2.5
 with the following individual added to the list of Contributing Authors
@@ -108,4 +108,4 @@
 
 Glenn Randers-Pehrson
 glennrp at users.sourceforge.net
-March 28, 2013
+April 25, 2013
diff --git a/README b/README
index fcf8f3f..26301a5 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-README for libpng version 1.6.1 - March 28, 2013 (shared library 16.0)
+README for libpng version 1.6.2 - April 25, 2013 (shared library 16.0)
 See the note about version numbers near the top of png.h
 
 See INSTALL for instructions on how to install libpng.
diff --git a/configure.ac b/configure.ac
index 1745d31..f9bc4f6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,7 +18,7 @@
 
 dnl Version number stuff here:
 
-AC_INIT([libpng],[1.6.1],[png-mng-implement@lists.sourceforge.net])
+AC_INIT([libpng],[1.6.2],[png-mng-implement@lists.sourceforge.net])
 AC_CONFIG_MACRO_DIR([scripts])
 
 # libpng does not follow GNU file name conventions (hence 'foreign')
@@ -39,10 +39,10 @@
 dnl AM_PREREQ([1.11.2])
 dnl stop configure from automagically running automake
 
-PNGLIB_VERSION=1.6.1
+PNGLIB_VERSION=1.6.2
 PNGLIB_MAJOR=1
 PNGLIB_MINOR=6
-PNGLIB_RELEASE=1
+PNGLIB_RELEASE=2
 
 dnl End of version number stuff
 
@@ -229,7 +229,7 @@
 # Because GCC by default assembles code with an executable stack, even though it
 # compiles C code with a non-executable stack, it is necessary to do a fixup
 # here (this may by GCC specific)
-AC_SUBST([AM_CCASFLAGS], [-Wa,--noexecstack])
+# AC_SUBST([AM_CCASFLAGS], [-Wa,--noexecstack])
 
 AC_ARG_ENABLE([arm-neon],
    AS_HELP_STRING([[[--enable-arm-neon]]],
diff --git a/contrib/libtests/pngunknown.c b/contrib/libtests/pngunknown.c
index 9b8de34..25452db 100644
--- a/contrib/libtests/pngunknown.c
+++ b/contrib/libtests/pngunknown.c
@@ -139,23 +139,128 @@
    { "PLTE", PNG_INFO_PLTE, png_PLTE, 0, 0, ABSENT, 0 },
 
    /* Non-critical chunks that libpng handles */
-   { "bKGD", PNG_INFO_bKGD, png_bKGD, 0, 1,  START, 0 },
-   { "cHRM", PNG_INFO_cHRM, png_cHRM, 0, 1,  START, 0 },
-   { "gAMA", PNG_INFO_gAMA, png_gAMA, 0, 1,  START, 0 },
-   { "hIST", PNG_INFO_hIST, png_hIST, 0, 1, ABSENT, 0 },
-   { "iCCP", PNG_INFO_iCCP, png_iCCP, 0, 1, ABSENT, 0 },
-   { "iTXt", PNG_INFO_iTXt, png_iTXt, 0, 1, ABSENT, 0 },
-   { "oFFs", PNG_INFO_oFFs, png_oFFs, 0, 1,  START, 0 },
-   { "pCAL", PNG_INFO_pCAL, png_pCAL, 0, 1,  START, 0 },
-   { "pHYs", PNG_INFO_pHYs, png_pHYs, 0, 1,  START, 0 },
-   { "sBIT", PNG_INFO_sBIT, png_sBIT, 0, 1,  START, 0 },
-   { "sCAL", PNG_INFO_sCAL, png_sCAL, 0, 1,  START, 0 },
-   { "sPLT", PNG_INFO_sPLT, png_sPLT, 0, 1, ABSENT, 0 },
-   { "sRGB", PNG_INFO_sRGB, png_sRGB, 0, 1,  START, 0 },
-   { "tEXt", PNG_INFO_tEXt, png_tEXt, 0, 1,  START, 0 },
-   { "tIME", PNG_INFO_tIME, png_tIME, 0, 1,  START, 0 },
-   { "tRNS", PNG_INFO_tRNS, png_tRNS, 0, 0, ABSENT, 0 },
-   { "zTXt", PNG_INFO_zTXt, png_zTXt, 0, 1,    END, 0 },
+   /* This is a mess but it seems to be the only way to do it - there is no way to
+    * check for definition outside a #if.
+    */
+   { "bKGD", PNG_INFO_bKGD, png_bKGD,
+#     ifdef PNG_READ_bKGD_SUPPORTED
+         0,
+#     else
+         1,
+#     endif
+      1,  START, 0 },
+   { "cHRM", PNG_INFO_cHRM, png_cHRM,
+#     ifdef PNG_READ_cHRM_SUPPORTED
+         0,
+#     else
+         1,
+#     endif
+      1,  START, 0 },
+   { "gAMA", PNG_INFO_gAMA, png_gAMA,
+#     ifdef PNG_READ_gAMA_SUPPORTED
+         0,
+#     else
+         1,
+#     endif
+      1,  START, 0 },
+   { "hIST", PNG_INFO_hIST, png_hIST,
+#     ifdef PNG_READ_hIST_SUPPORTED
+         0,
+#     else
+         1,
+#     endif
+      1, ABSENT, 0 },
+   { "iCCP", PNG_INFO_iCCP, png_iCCP,
+#     ifdef PNG_READ_iCCP_SUPPORTED
+         0,
+#     else
+         1,
+#     endif
+      1, ABSENT, 0 },
+   { "iTXt", PNG_INFO_iTXt, png_iTXt,
+#     ifdef PNG_READ_iTXt_SUPPORTED
+         0,
+#     else
+         1,
+#     endif
+      1, ABSENT, 0 },
+   { "oFFs", PNG_INFO_oFFs, png_oFFs,
+#     ifdef PNG_READ_oFFs_SUPPORTED
+         0,
+#     else
+         1,
+#     endif
+      1,  START, 0 },
+   { "pCAL", PNG_INFO_pCAL, png_pCAL,
+#     ifdef PNG_READ_pCAL_SUPPORTED
+         0,
+#     else
+         1,
+#     endif
+      1,  START, 0 },
+   { "pHYs", PNG_INFO_pHYs, png_pHYs,
+#     ifdef PNG_READ_pHYs_SUPPORTED
+         0,
+#     else
+         1,
+#     endif
+      1,  START, 0 },
+   { "sBIT", PNG_INFO_sBIT, png_sBIT,
+#     ifdef PNG_READ_sBIT_SUPPORTED
+         0,
+#     else
+         1,
+#     endif
+      1,  START, 0 },
+   { "sCAL", PNG_INFO_sCAL, png_sCAL,
+#     ifdef PNG_READ_sCAL_SUPPORTED
+         0,
+#     else
+         1,
+#     endif
+      1,  START, 0 },
+   { "sPLT", PNG_INFO_sPLT, png_sPLT,
+#     ifdef PNG_READ_sPLT_SUPPORTED
+         0,
+#     else
+         1,
+#     endif
+      1, ABSENT, 0 },
+   { "sRGB", PNG_INFO_sRGB, png_sRGB,
+#     ifdef PNG_READ_sRGB_SUPPORTED
+         0,
+#     else
+         1,
+#     endif
+      1,  START, 0 },
+   { "tEXt", PNG_INFO_tEXt, png_tEXt,
+#     ifdef PNG_READ_tEXt_SUPPORTED
+         0,
+#     else
+         1,
+#     endif
+      1,  START, 0 },
+   { "tIME", PNG_INFO_tIME, png_tIME,
+#     ifdef PNG_READ_tIME_SUPPORTED
+         0,
+#     else
+         1,
+#     endif
+      1,  START, 0 },
+   { "tRNS", PNG_INFO_tRNS, png_tRNS,
+#     ifdef PNG_READ_tRNS_SUPPORTED
+         0,
+#     else
+         1,
+#     endif
+      0, ABSENT, 0 },
+   { "zTXt", PNG_INFO_zTXt, png_zTXt,
+#     ifdef PNG_READ_zTXt_SUPPORTED
+         0,
+#     else
+         1,
+#     endif
+      1,    END, 0 },
 
    /* No libpng handling */
    { "sTER", PNG_INFO_sTER, png_sTER, 1, 1,  START, 0 },
@@ -955,6 +1060,7 @@
 {
    fprintf(stderr,
    " test ignored because libpng was not built with unknown chunk support\n");
-   return 0;
+   /* So the test is skipped: */
+   return 77;
 }
 #endif
diff --git a/contrib/libtests/pngvalid.c b/contrib/libtests/pngvalid.c
index f36b1f8..fbd6778 100644
--- a/contrib/libtests/pngvalid.c
+++ b/contrib/libtests/pngvalid.c
@@ -4599,9 +4599,13 @@
       }
       else
          png_progressive_combine_row(pp, row, new_row);
-   } else if (dp->interlace_type == PNG_INTERLACE_ADAM7 &&
-      PNG_ROW_IN_INTERLACE_PASS(y, pass) &&
-      PNG_PASS_COLS(dp->w, pass) > 0)
+#endif /* PNG_READ_INTERLACING_SUPPORTED */
+   }
+
+#ifdef PNG_READ_INTERLACING_SUPPORTED
+   else if (dp->interlace_type == PNG_INTERLACE_ADAM7 &&
+       PNG_ROW_IN_INTERLACE_PASS(y, pass) &&
+       PNG_PASS_COLS(dp->w, pass) > 0)
       png_error(pp, "missing row in progressive de-interlacing");
 #endif /* PNG_READ_INTERLACING_SUPPORTED */
 }
@@ -10135,6 +10139,7 @@
 int main(void)
 {
    fprintf(stderr, "pngvalid: no write support in libpng, all tests skipped\n");
-   return 0;
+   /* So the test is skipped: */
+   return 77;
 }
 #endif
diff --git a/contrib/tools/fixitxt.c b/contrib/tools/fixitxt.c
new file mode 100644
index 0000000..d717b3e
--- /dev/null
+++ b/contrib/tools/fixitxt.c
@@ -0,0 +1,144 @@
+#include <stdio.h>
+
+/* fixitxt version 1.0.0
+ *
+ * Copyright 2013 Glenn Randers-Pehrson
+ *
+ * This code is released under the libpng license.
+ * For conditions of distribution and use, see the disclaimer
+ * and license in png.h
+ *
+ * Usage:            
+ *
+ *     fixitxt.exe < bad.png > good.png
+ *
+ * Fixes a PNG file written with libpng-1.6.0 or 1.6.1 that has one or more
+ * uncompressed iTXt chunks.  Assumes that the actual length is greater
+ * than or equal to the value in the length byte, and that the CRC is
+ * correct for the actual length.  This program hunts for the CRC and
+ * adjusts the length byte accordingly.  It is not an error to process a
+ * PNG file that has no iTXt chunks or one that has valid iTXt chunks;
+ * such files will simply be copied.
+ *
+ * Requires zlib (for crc32 and Z_NULL); build with
+ *
+ *     gcc -O -o fixitxt fixitxt.c -lz
+ */
+
+#define MAX_LENGTH 500000
+
+#define GETBREAK c=getchar(); if (c == EOF) break;
+#include <zlib.h>
+
+main()
+{
+   unsigned int i;
+   unsigned char buf[MAX_LENGTH];
+   unsigned long crc;
+   unsigned int c;
+
+/* Skip 8-byte signature */
+   for (i=8; i; i--)
+   {
+      c=GETBREAK;
+      putchar(c);
+   }
+
+if (c != EOF)
+for (;;)
+ {
+   /* Read the length */
+   unsigned long length;
+   c=GETBREAK; buf[0] = c;
+   c=GETBREAK; buf[1] = c;
+   c=GETBREAK; buf[2] = c;
+   c=GETBREAK; buf[3] = c;
+
+   length=((((unsigned long) buf[0]<<8 + buf[1]<<16) + buf[2] << 8) + buf[3]);
+   /* Read the chunkname */
+   c=GETBREAK; buf[4] = c;
+   c=GETBREAK; buf[5] = c;
+   c=GETBREAK; buf[6] = c;
+   c=GETBREAK; buf[7] = c;
+
+
+   /* The iTXt chunk type expressed as integers is (105, 84, 88, 116) */
+   if (buf[4] == 105 && buf[5] == 84 && buf[6] == 88 && buf[7] == 116)
+   {
+      if (length >= MAX_LENGTH-12)
+         break;  /* To do: handle this more gracefully */
+
+      /* Initialize the CRC */
+      crc = crc32(0, Z_NULL, 0);
+
+      /* Copy the data bytes */
+      for (i=8; i < length + 12; i++)
+      {
+         c=GETBREAK; buf[i] = c;
+      }
+
+      /* Calculate the CRC */
+      crc = crc32(crc, buf+4, (uInt)length+4);
+
+      for (;;)
+      {
+        /* Check the CRC */
+        if (((crc >> 24) & 0xff) == buf[length+8] &&
+            ((crc >> 16) & 0xff) == buf[length+9] &&
+            ((crc >>  8) & 0xff) == buf[length+10] &&
+            ((crc      ) & 0xff) == buf[length+11])
+           break;
+
+        length++;
+
+        if (length >= MAX_LENGTH-12)
+           break;
+
+        c=GETBREAK;
+        buf[length+11]=c;
+
+        /* Update the CRC */
+        crc = crc32(crc, buf+7+length, 1);
+      }
+
+      /* Update length bytes */
+        buf[0] = (length << 24) & 0xff;
+        buf[1] = (length << 16) & 0xff;
+        buf[2] = (length <<  8) & 0xff;
+        buf[3] = (length      ) & 0xff;
+
+      /* Write the fixed iTXt chunk (length, name, data, crc) */
+      for (i=0; i<length+12; i++)
+         putchar(buf[i]);
+   }
+
+   else
+   {
+      /* Copy bytes that were already read (length and chunk name) */
+      for (i=0; i<8; i++)
+         putchar(buf[i]);
+
+      /* Copy data bytes and CRC */
+      for (i=8; i< length+12; i++)
+      {
+         c=GETBREAK;
+         putchar(c);
+      }
+
+      if (c == EOF)
+      {
+         break;
+      }
+
+   /* The IEND chunk type expressed as integers is (73, 69, 78, 68) */
+      if (buf[4] == 73 && buf[5] == 69 && buf[6] == 78 && buf[7] == 68)
+         break;
+   }
+
+   if (c == EOF)
+      break;
+
+   if (buf[4] == 73 && buf[5] == 69 && buf[6] == 78 && buf[7] == 68)
+     break;
+ }
+}
diff --git a/libpng-manual.txt b/libpng-manual.txt
index 4b91d86..53829be 100644
--- a/libpng-manual.txt
+++ b/libpng-manual.txt
@@ -1,6 +1,6 @@
 libpng-manual.txt - A description on how to use and modify libpng
 
- libpng version 1.6.1 - March 28, 2013
+ libpng version 1.6.2 - April 25, 2013
  Updated and distributed by Glenn Randers-Pehrson
  <glennrp at users.sourceforge.net>
  Copyright (c) 1998-2013 Glenn Randers-Pehrson
@@ -11,7 +11,7 @@
 
  Based on:
 
- libpng versions 0.97, January 1998, through 1.6.1 - March 28, 2013
+ libpng versions 0.97, January 1998, through 1.6.2 - April 25, 2013
  Updated and distributed by Glenn Randers-Pehrson
  Copyright (c) 1998-2013 Glenn Randers-Pehrson
 
@@ -4978,7 +4978,11 @@
 Error detection in some chunks has improved; in particular the iCCP chunk
 reader now does pretty complete validation of the basic format.  Some bad
 profiles that were previously accepted are now rejected, in particular the
-very old broken Microsoft/HP sRGB profile.
+very old broken Microsoft/HP sRGB profile.  The PNG spec requirement that
+only grayscale profiles may appear in images with color type 0 or 4 and that
+even if the image only contains gray pixels, only RGB profiles may appear
+in images with color type 2, 3, or 6, is now enforced.  The sRGB chunk
+is allowed to appear in images with any color type.
 
 The library now issues an error if the application attempts to set a
 transform after it calls png_read_update_info().
@@ -5015,11 +5019,11 @@
 going back to version 0.70.  You can access the git repository (read only)
 at
 
-    git://libpng.git.sourceforge.net/gitroot/libpng
+    git://git.code.sf.net/p/libpng/code
 
-or you can browse it via "gitweb" at
+or you can browse it with a web browser by selecting the "code" button at
 
-    http://libpng.git.sourceforge.net/git/gitweb.cgi?p=libpng
+    https://sourceforge.net/projects/libpng
 
 Patches can be sent to glennrp at users.sourceforge.net or to
 png-mng-implement at lists.sourceforge.net or you can upload them to
@@ -5161,13 +5165,13 @@
 
 XVI. Y2K Compliance in libpng
 
-March 28, 2013
+April 25, 2013
 
 Since the PNG Development group is an ad-hoc body, we can't make
 an official declaration.
 
 This is your unofficial assurance that libpng from version 0.71 and
-upward through 1.6.1 are Y2K compliant.  It is my belief that earlier
+upward through 1.6.2 are Y2K compliant.  It is my belief that earlier
 versions were also Y2K compliant.
 
 Libpng only has two year fields.  One is a 2-byte unsigned integer
diff --git a/libpng.3 b/libpng.3
index e4f4e94..bbf2eaa 100644
--- a/libpng.3
+++ b/libpng.3
@@ -1,6 +1,6 @@
-.TH LIBPNG 3 "March 28, 2013"
+.TH LIBPNG 3 "April 25, 2013"
 .SH NAME
-libpng \- Portable Network Graphics (PNG) Reference Library 1.6.1
+libpng \- Portable Network Graphics (PNG) Reference Library 1.6.2
 .SH SYNOPSIS
 \fB
 #include <png.h>\fP
@@ -504,7 +504,7 @@
 .SH LIBPNG.TXT
 libpng-manual.txt - A description on how to use and modify libpng
 
- libpng version 1.6.1 - March 28, 2013
+ libpng version 1.6.2 - April 25, 2013
  Updated and distributed by Glenn Randers-Pehrson
  <glennrp at users.sourceforge.net>
  Copyright (c) 1998-2013 Glenn Randers-Pehrson
@@ -515,7 +515,7 @@
 
  Based on:
 
- libpng versions 0.97, January 1998, through 1.6.1 - March 28, 2013
+ libpng versions 0.97, January 1998, through 1.6.2 - April 25, 2013
  Updated and distributed by Glenn Randers-Pehrson
  Copyright (c) 1998-2013 Glenn Randers-Pehrson
 
@@ -5483,7 +5483,11 @@
 Error detection in some chunks has improved; in particular the iCCP chunk
 reader now does pretty complete validation of the basic format.  Some bad
 profiles that were previously accepted are now rejected, in particular the
-very old broken Microsoft/HP sRGB profile.
+very old broken Microsoft/HP sRGB profile.  The PNG spec requirement that
+only grayscale profiles may appear in images with color type 0 or 4 and that
+even if the image only contains gray pixels, only RGB profiles may appear
+in images with color type 2, 3, or 6, is now enforced.  The sRGB chunk
+is allowed to appear in images with any color type.
 
 The library now issues an error if the application attempts to set a
 transform after it calls png_read_update_info().
@@ -5520,11 +5524,11 @@
 going back to version 0.70.  You can access the git repository (read only)
 at
 
-    git://libpng.git.sourceforge.net/gitroot/libpng
+    git://git.code.sf.net/p/libpng/code
 
-or you can browse it via "gitweb" at
+or you can browse it with a web browser by selecting the "code" button at
 
-    http://libpng.git.sourceforge.net/git/gitweb.cgi?p=libpng
+    https://sourceforge.net/projects/libpng
 
 Patches can be sent to glennrp at users.sourceforge.net or to
 png-mng-implement at lists.sourceforge.net or you can upload them to
@@ -5666,13 +5670,13 @@
 
 .SH XVI. Y2K Compliance in libpng
 
-March 28, 2013
+April 25, 2013
 
 Since the PNG Development group is an ad-hoc body, we can't make
 an official declaration.
 
 This is your unofficial assurance that libpng from version 0.71 and
-upward through 1.6.1 are Y2K compliant.  It is my belief that earlier
+upward through 1.6.2 are Y2K compliant.  It is my belief that earlier
 versions were also Y2K compliant.
 
 Libpng only has two year fields.  One is a 2-byte unsigned integer
@@ -5880,8 +5884,12 @@
  1.6.0beta01-40      16    10600  16.so.16.0[.0]
  1.6.0rc01-08        16    10600  16.so.16.0[.0]
  1.6.0               16    10600  16.so.16.0[.0]
+ 1.6.1beta01-09      16    10601  16.so.16.1[.0]
  1.6.1rc01           16    10601  16.so.16.1[.0]
  1.6.1               16    10601  16.so.16.1[.0]
+ 1.6.2beta01         16    10602  16.so.16.2[.0]
+ 1.6.2rc01-06        16    10602  16.so.16.2[.0]
+ 1.6.2               16    10602  16.so.16.2[.0]
 
 Henceforth the source version will match the shared-library minor
 and patch numbers; the shared-library major version number will be
@@ -5938,7 +5946,7 @@
 
 Thanks to Frank J. T. Wojcik for helping with the documentation.
 
-Libpng version 1.6.1 - March 28, 2013:
+Libpng version 1.6.2 - April 25, 2013:
 Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
 Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
 
@@ -5961,7 +5969,7 @@
 
 This code is released under the libpng license.
 
-libpng versions 1.2.6, August 15, 2004, through 1.6.1, March 28, 2013, are
+libpng versions 1.2.6, August 15, 2004, through 1.6.2, April 25, 2013, are
 Copyright (c) 2004,2006-2007 Glenn Randers-Pehrson, and are
 distributed according to the same disclaimer and license as libpng-1.2.5
 with the following individual added to the list of Contributing Authors
@@ -6060,7 +6068,7 @@
 
 Glenn Randers-Pehrson
 glennrp at users.sourceforge.net
-March 28, 2013
+April 25, 2013
 
 .\" end of man page
 
diff --git a/libpngpf.3 b/libpngpf.3
index 21b56cf..7baaa22 100644
--- a/libpngpf.3
+++ b/libpngpf.3
@@ -1,6 +1,6 @@
-.TH LIBPNGPF 3 "March 28, 2013"
+.TH LIBPNGPF 3 "April 25, 2013"
 .SH NAME
-libpng \- Portable Network Graphics (PNG) Reference Library 1.6.1
+libpng \- Portable Network Graphics (PNG) Reference Library 1.6.2
 (private functions)
 .SH SYNOPSIS
 \fB#include \fI"pngpriv.h"
diff --git a/png.5 b/png.5
index 1d25bf5..e14e7da 100644
--- a/png.5
+++ b/png.5
@@ -1,4 +1,4 @@
-.TH PNG 5 "March 28, 2013"
+.TH PNG 5 "April 25, 2013"
 .SH NAME
 png \- Portable Network Graphics (PNG) format
 .SH DESCRIPTION
diff --git a/png.c b/png.c
index 67f760e..d429c52 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.1 [March 28, 2013]
+ * Last changed in libpng 1.6.2 [April 25, 2013]
  * Copyright (c) 1998-2013 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.)
@@ -14,7 +14,7 @@
 #include "pngpriv.h"
 
 /* Generate a compiler error if there is an old png.h in the search path. */
-typedef png_libpng_version_1_6_1 Your_png_h_is_not_version_1_6_1;
+typedef png_libpng_version_1_6_2 Your_png_h_is_not_version_1_6_2;
 
 /* Tells libpng that we have already handled the first "num_bytes" bytes
  * of the PNG file signature.  If the PNG data is embedded into another
@@ -115,7 +115,7 @@
 {
    int need_crc = 1;
 
-   if (PNG_CHUNK_ANCILLIARY(png_ptr->chunk_name))
+   if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name))
    {
       if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
           (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
@@ -768,13 +768,13 @@
 #else
 #  ifdef __STDC__
    return PNG_STRING_NEWLINE \
-     "libpng version 1.6.1 - March 28, 2013" PNG_STRING_NEWLINE \
+     "libpng version 1.6.2 - April 25, 2013" PNG_STRING_NEWLINE \
      "Copyright (c) 1998-2013 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.1 - March 28, 2013\
+      return "libpng version 1.6.2 - April 25, 2013\
       Copyright (c) 1998-2013 Glenn Randers-Pehrson\
       Copyright (c) 1996-1997 Andreas Dilger\
       Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
@@ -1866,7 +1866,7 @@
          "length does not match profile");
 
    temp = png_get_uint_32(profile+128); /* tag count: 12 bytes/tag */
-   if (temp > 357913930 || /* (2^32-4-132)/12: maxium possible tag count */
+   if (temp > 357913930 || /* (2^32-4-132)/12: maximum possible tag count */
       profile_length < 132+12*temp) /* truncated tag table */
       return png_icc_profile_error(png_ptr, colorspace, name, temp,
          "tag count too large");
@@ -2275,7 +2275,10 @@
       png_icc_check_tag_table(png_ptr, colorspace, name, profile_length,
          profile))
    {
-      png_icc_set_sRGB(png_ptr, colorspace, profile, 0);
+#     ifdef PNG_sRGB_SUPPORTED
+         /* If no sRGB support, don't try storing sRGB information */
+         png_icc_set_sRGB(png_ptr, colorspace, profile, 0);
+#     endif
       return 1;
    }
 
diff --git a/png.h b/png.h
index 0ad09eb..0b5053f 100644
--- a/png.h
+++ b/png.h
@@ -1,7 +1,7 @@
 
 /* png.h - header file for PNG reference library
  *
- * libpng version 1.6.1 - March 28, 2013
+ * libpng version 1.6.2 - April 25, 2013
  * Copyright (c) 1998-2013 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.)
@@ -11,7 +11,7 @@
  * Authors and maintainers:
  *   libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
  *   libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger
- *   libpng versions 0.97, January 1998, through 1.6.1 - March 28, 2013: Glenn
+ *   libpng versions 0.97, January 1998, through 1.6.2 - April 25, 2013: Glenn
  *   See also "Contributing Authors", below.
  *
  * Note about libpng version numbers:
@@ -169,9 +169,12 @@
  *    1.6.0beta01-40          16    10600  16.so.16.0[.0]
  *    1.6.0rc01-08            16    10600  16.so.16.0[.0]
  *    1.6.0                   16    10600  16.so.16.0[.0]
- *    1.6.1beta01-10          16    10601  16.so.16.1[.0]
+ *    1.6.1beta01-09          16    10601  16.so.16.1[.0]
  *    1.6.1rc01               16    10601  16.so.16.1[.0]
  *    1.6.1                   16    10601  16.so.16.1[.0]
+ *    1.6.2beta01             16    10602  16.so.16.2[.0]
+ *    1.6.2rc01-06            16    10602  16.so.16.2[.0]
+ *    1.6.2                   16    10602  16.so.16.2[.0]
  *
  *   Henceforth the source version will match the shared-library major
  *   and minor numbers; the shared-library major version number will be
@@ -203,7 +206,7 @@
  *
  * This code is released under the libpng license.
  *
- * libpng versions 1.2.6, August 15, 2004, through 1.6.1, March 28, 2013, are
+ * libpng versions 1.2.6, August 15, 2004, through 1.6.2, April 25, 2013, are
  * Copyright (c) 2004, 2006-2013 Glenn Randers-Pehrson, and are
  * distributed according to the same disclaimer and license as libpng-1.2.5
  * with the following individual added to the list of Contributing Authors:
@@ -315,13 +318,13 @@
  * Y2K compliance in libpng:
  * =========================
  *
- *    March 28, 2013
+ *    April 25, 2013
  *
  *    Since the PNG Development group is an ad-hoc body, we can't make
  *    an official declaration.
  *
  *    This is your unofficial assurance that libpng from version 0.71 and
- *    upward through 1.6.1 are Y2K compliant.  It is my belief that
+ *    upward through 1.6.2 are Y2K compliant.  It is my belief that
  *    earlier versions were also Y2K compliant.
  *
  *    Libpng only has two year fields.  One is a 2-byte unsigned integer
@@ -381,9 +384,9 @@
  */
 
 /* Version information for png.h - this should match the version in png.c */
-#define PNG_LIBPNG_VER_STRING "1.6.1"
+#define PNG_LIBPNG_VER_STRING "1.6.2"
 #define PNG_HEADER_VERSION_STRING \
-     " libpng version 1.6.1 - March 28, 2013\n"
+     " libpng version 1.6.2 - April 25, 2013\n"
 
 #define PNG_LIBPNG_VER_SONUM   16
 #define PNG_LIBPNG_VER_DLLNUM  16
@@ -391,7 +394,7 @@
 /* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
 #define PNG_LIBPNG_VER_MAJOR   1
 #define PNG_LIBPNG_VER_MINOR   6
-#define PNG_LIBPNG_VER_RELEASE 1
+#define PNG_LIBPNG_VER_RELEASE 2
 
 /* This should match the numeric part of the final component of
  * PNG_LIBPNG_VER_STRING, omitting any leading zero:
@@ -422,7 +425,7 @@
  * version 1.0.0 was mis-numbered 100 instead of 10000).  From
  * version 1.0.1 it's    xxyyzz, where x=major, y=minor, z=release
  */
-#define PNG_LIBPNG_VER 10601 /* 1.6.1 */
+#define PNG_LIBPNG_VER 10602 /* 1.6.2 */
 
 /* Library configuration: these options cannot be changed after
  * the library has been built.
@@ -527,7 +530,7 @@
 /* This triggers a compiler error in png.c, if png.c and png.h
  * do not agree upon the version number.
  */
-typedef char* png_libpng_version_1_6_1;
+typedef char* png_libpng_version_1_6_2;
 
 /* Basic control structions.  Read libpng-manual.txt or libpng.3 for more info.
  *
diff --git a/pngconf.h b/pngconf.h
index d9dbff0..31f9967 100644
--- a/pngconf.h
+++ b/pngconf.h
@@ -1,7 +1,7 @@
 
 /* pngconf.h - machine configurable file for libpng
  *
- * libpng version 1.6.1 - March 28, 2013
+ * libpng version 1.6.2 - April 25, 2013
  *
  * Copyright (c) 1998-2013 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngpriv.h b/pngpriv.h
index 35e7edd..d06284d 100644
--- a/pngpriv.h
+++ b/pngpriv.h
@@ -6,7 +6,7 @@
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  *
- * Last changed in libpng 1.6.1 [March 28, 2013]
+ * Last changed in libpng 1.6.2 [April 25, 2013]
  *
  * This code is released under the libpng license.
  * For conditions of distribution and use, see the disclaimer
@@ -675,8 +675,8 @@
    (void)(PNG_STRING_FROM_CHUNK(s,c), ((char*)(s))[4] = 0)
 
 /* Test on flag values as defined in the spec (section 5.4): */
-#define PNG_CHUNK_ANCILLIARY(c)   (1 & ((c) >> 29))
-#define PNG_CHUNK_CRITICAL(c)     (!PNG_CHUNK_ANCILLIARY(c))
+#define PNG_CHUNK_ANCILLARY(c)   (1 & ((c) >> 29))
+#define PNG_CHUNK_CRITICAL(c)     (!PNG_CHUNK_ANCILLARY(c))
 #define PNG_CHUNK_PRIVATE(c)      (1 & ((c) >> 21))
 #define PNG_CHUNK_RESERVED(c)     (1 & ((c) >> 13))
 #define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >>  5))
diff --git a/pngrtran.c b/pngrtran.c
index 626f3b0..e378ceb 100644
--- a/pngrtran.c
+++ b/pngrtran.c
@@ -1,7 +1,7 @@
 
 /* pngrtran.c - transforms the data in a row for PNG readers
  *
- * Last changed in libpng 1.6.1 [March 28, 2013]
+ * Last changed in libpng 1.6.2 [April 25, 2013]
  * Copyright (c) 1998-2013 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.)
@@ -223,6 +223,8 @@
        */
 #     ifdef PNG_READ_sRGB_SUPPORTED
          png_ptr->flags |= PNG_FLAG_ASSUME_sRGB;
+#     else
+         PNG_UNUSED(png_ptr)
 #     endif
       if (is_screen)
          output_gamma = PNG_GAMMA_sRGB;
@@ -1056,9 +1058,6 @@
 {
    png_debug(1, "in png_set_read_user_transform_fn");
 
-   if (!png_rtran_ok(png_ptr, 0))
-      return;
-
 #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
    png_ptr->transformations |= PNG_USER_TRANSFORM;
    png_ptr->read_user_transform_fn = read_user_transform_fn;
diff --git a/pngrutil.c b/pngrutil.c
index 3f4474c..01c3679 100644
--- a/pngrutil.c
+++ b/pngrutil.c
@@ -1,7 +1,7 @@
 
 /* pngrutil.c - utilities to read a PNG file
  *
- * Last changed in libpng 1.6.1 [March 28, 2013]
+ * Last changed in libpng 1.6.2 [April 25, 2013]
  * Copyright (c) 1998-2013 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.)
@@ -221,7 +221,7 @@
 
    if (png_crc_error(png_ptr))
    {
-      if (PNG_CHUNK_ANCILLIARY(png_ptr->chunk_name) ?
+      if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) ?
           !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) :
           (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE))
       {
@@ -250,7 +250,7 @@
    png_uint_32 crc;
    int need_crc = 1;
 
-   if (PNG_CHUNK_ANCILLIARY(png_ptr->chunk_name))
+   if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name))
    {
       if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
           (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
@@ -2857,7 +2857,7 @@
 
          if (keep == PNG_HANDLE_CHUNK_ALWAYS ||
             (keep == PNG_HANDLE_CHUNK_IF_SAFE &&
-             PNG_CHUNK_ANCILLIARY(png_ptr->chunk_name)))
+             PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)))
          {
             if (!png_cache_unknown_chunk(png_ptr, length))
                keep = PNG_HANDLE_CHUNK_NEVER;
@@ -2891,7 +2891,7 @@
        */
       if (keep == PNG_HANDLE_CHUNK_ALWAYS ||
          (keep == PNG_HANDLE_CHUNK_IF_SAFE &&
-          PNG_CHUNK_ANCILLIARY(png_ptr->chunk_name)))
+          PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)))
       {
 #     ifdef PNG_USER_LIMITS_SUPPORTED
          switch (png_ptr->user_chunk_cache_max)
@@ -3875,7 +3875,7 @@
     * the filter is the first transformation performed on the row data.  It is
     * performed in place, therefore an implementation can be selected based on
     * the image pixel format.  If the implementation depends on image width then
-    * take care to ensure that it works corretly if the image is interlaced -
+    * take care to ensure that it works correctly if the image is interlaced -
     * interlacing causes the actual row width to vary.
     */
 {
@@ -3983,7 +3983,7 @@
          png_ptr->zstream.avail_out = out;
       }
 
-      else /* check for end */
+      else /* after last row, checking for end */
       {
          png_ptr->zstream.next_out = tmpbuf;
          png_ptr->zstream.avail_out = (sizeof tmpbuf);
@@ -3998,10 +3998,13 @@
        */
       ret = inflate(&png_ptr->zstream, Z_NO_FLUSH);
 
-      /* Take the unconsumed output back (so, in the 'check' case this just
-       * counts up).
-       */
-      avail_out += png_ptr->zstream.avail_out;
+      /* Take the unconsumed output back. */
+      if (output != NULL)
+         avail_out += png_ptr->zstream.avail_out;
+
+      else /* avail_out counts the extra bytes */
+         avail_out += (sizeof tmpbuf) - png_ptr->zstream.avail_out;
+
       png_ptr->zstream.avail_out = 0;
 
       if (ret == Z_STREAM_END)
@@ -4040,7 +4043,7 @@
       if (output != NULL)
          png_error(png_ptr, "Not enough image data");
 
-      else /* checking */
+      else /* the deflate stream contained extra data */
          png_chunk_benign_error(png_ptr, "Too much image data");
    }
 }
diff --git a/pngset.c b/pngset.c
index c88d621..fcb0779 100644
--- a/pngset.c
+++ b/pngset.c
@@ -1,7 +1,7 @@
 
 /* pngset.c - storage of image information into info struct
  *
- * Last changed in libpng 1.6.1 [March 28, 2013]
+ * Last changed in libpng 1.6.2 [April 25, 2013]
  * Copyright (c) 1998-2013 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.)
diff --git a/pngtest.c b/pngtest.c
index fd0e817..144f2db 100644
--- a/pngtest.c
+++ b/pngtest.c
@@ -1,7 +1,7 @@
 
 /* pngtest.c - a simple test program to test libpng
  *
- * Last changed in libpng 1.6.1 [March 28, 2013]
+ * Last changed in libpng 1.6.2 [April 25, 2013]
  * Copyright (c) 1998-2013 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.)
@@ -43,7 +43,23 @@
 
 #include "png.h"
 
-#ifdef PNG_READ_SUPPORTED /* else nothing can be done */
+/* Known chunks that exist in pngtest.png must be supported or pngtest will fail
+ * simply as a result of re-ordering them.  This may be fixed in 1.7
+ */
+#if defined PNG_READ_SUPPORTED && /* else nothing can be done */\
+   defined PNG_READ_bKGD_SUPPORTED &&\
+   defined PNG_READ_cHRM_SUPPORTED &&\
+   defined PNG_READ_gAMA_SUPPORTED &&\
+   defined PNG_READ_oFFs_SUPPORTED &&\
+   defined PNG_READ_pCAL_SUPPORTED &&\
+   defined PNG_READ_pHYs_SUPPORTED &&\
+   defined PNG_READ_sBIT_SUPPORTED &&\
+   defined PNG_READ_sCAL_SUPPORTED &&\
+   defined PNG_READ_sRGB_SUPPORTED &&\
+   defined PNG_READ_tEXt_SUPPORTED &&\
+   defined PNG_READ_tIME_SUPPORTED &&\
+   defined PNG_READ_zTXt_SUPPORTED
+
 #include "zlib.h"
 /* Copied from pngpriv.h but only used in error messages below. */
 #ifndef PNG_ZBUF_SIZE
@@ -1173,7 +1189,8 @@
    }
 #endif
 #ifdef PNG_sCAL_SUPPORTED
-#ifdef PNG_FLOATING_POINT_SUPPORTED
+#if defined(PNG_FLOATING_POINT_SUPPORTED) && \
+   defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)
    {
       int unit;
       double scal_width, scal_height;
@@ -1945,9 +1962,10 @@
 {
    fprintf(STDERR,
       " test ignored because libpng was not built with read support\n");
-   return 0;
+   /* And skip this test */
+   return 77;
 }
 #endif
 
 /* Generate a compiler error if there is an old png.h in the search path. */
-typedef png_libpng_version_1_6_1 Your_png_h_is_not_version_1_6_1;
+typedef png_libpng_version_1_6_2 Your_png_h_is_not_version_1_6_2;
diff --git a/pngtrans.c b/pngtrans.c
index b532172..8f8bc5d 100644
--- a/pngtrans.c
+++ b/pngtrans.c
@@ -1,7 +1,7 @@
 
 /* pngtrans.c - transforms the data in a row (used by both readers and writers)
  *
- * Last changed in libpng 1.6.0 [February 14, 2013]
+ * Last changed in libpng 1.6.2 [April 25, 2013]
  * Copyright (c) 1998-2013 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.)
@@ -782,6 +782,17 @@
 
    if (png_ptr == NULL)
       return;
+
+#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
+   if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 &&
+      (png_ptr->flags & PNG_FLAG_ROW_INIT) != 0)
+   {
+      png_app_error(png_ptr,
+            "info change after png_start_read_image or png_read_update_info");
+      return;
+   }
+#endif
+
    png_ptr->user_transform_ptr = user_transform_ptr;
    png_ptr->user_transform_depth = (png_byte)user_transform_depth;
    png_ptr->user_transform_channels = (png_byte)user_transform_channels;
diff --git a/pngwrite.c b/pngwrite.c
index b0887bd..33924aa 100644
--- a/pngwrite.c
+++ b/pngwrite.c
@@ -1,7 +1,7 @@
 
 /* pngwrite.c - general routines to write a PNG file
  *
- * Last changed in libpng 1.6.1 [March 28, 2013]
+ * Last changed in libpng 1.6.2 [April 25, 2013]
  * Copyright (c) 1998-2013 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.)
diff --git a/pngwutil.c b/pngwutil.c
index 8c49cfd..49e6a2d 100644
--- a/pngwutil.c
+++ b/pngwutil.c
@@ -1,7 +1,7 @@
 
 /* pngwutil.c - utilities to write a PNG file
  *
- * Last changed in libpng 1.6.0 [February 14, 2013]
+ * Last changed in libpng 1.6.2 [April 25, 2013]
  * Copyright (c) 1998-2013 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.)
@@ -1744,6 +1744,9 @@
    {
       if (comp.input_len > PNG_UINT_31_MAX-prefix_len)
          png_error(png_ptr, "iTXt: uncompressed text too long");
+
+      /* So the string will fit in a chunk: */
+      comp.output_len = (png_uint_32)/*SAFE*/comp.input_len;
    }
 
    png_write_chunk_header(png_ptr, png_iTXt, comp.output_len + prefix_len);
diff --git a/projects/vstudio/readme.txt b/projects/vstudio/readme.txt
index bc16eb1..1af61c9 100644
--- a/projects/vstudio/readme.txt
+++ b/projects/vstudio/readme.txt
@@ -1,7 +1,7 @@
 
 VisualStudio instructions
 
-libpng version 1.6.1 - March 28, 2013
+libpng version 1.6.2 - April 25, 2013
 
 Copyright (c) 1998-2010 Glenn Randers-Pehrson
 
diff --git a/projects/vstudio/zlib.props b/projects/vstudio/zlib.props
index 8e92fdc..c73bf08 100644
--- a/projects/vstudio/zlib.props
+++ b/projects/vstudio/zlib.props
@@ -2,7 +2,7 @@
 <!--
  * zlib.props - location of zlib source
  *
- * libpng version 1.6.1 - March 28, 2013
+ * libpng version 1.6.2 - April 25, 2013
  *
  * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  *
diff --git a/scripts/README.txt b/scripts/README.txt
index 27b5e52..6f5f062 100644
--- a/scripts/README.txt
+++ b/scripts/README.txt
@@ -1,9 +1,9 @@
 
-Makefiles for  libpng version 1.6.1 - March 28, 2013
+Makefiles for  libpng version 1.6.2 - April 25, 2013
 
 pnglibconf.h.prebuilt       =>  Stores configuration settings
  makefile.linux    =>  Linux/ELF makefile
-                       (gcc, creates libpng16.so.16.1.6.1)
+                       (gcc, creates libpng16.so.16.1.6.2)
  makefile.gcc      =>  Generic makefile (gcc, creates static libpng.a)
  makefile.knr      =>  Archaic UNIX Makefile that converts files with
                        ansi2knr (Requires ansi2knr.c from
@@ -20,7 +20,7 @@
  makefile.dec      =>  DEC Alpha UNIX makefile
  makefile.dj2      =>  DJGPP 2 makefile
  makefile.elf      =>  Linux/ELF makefile symbol versioning,
-                       (gcc, creates libpng16.so.16.1.6.1)
+                       (gcc, creates libpng16.so.16.1.6.2)
  makefile.freebsd  =>  FreeBSD makefile
  makefile.gcc      =>  Generic gcc makefile
  makefile.hpgcc    =>  HPUX makefile using gcc
@@ -35,12 +35,12 @@
  makefile.os2      =>  OS/2 Makefile (gcc and emx, requires libpng.def)
  makefile.sco      =>  For SCO OSr5  ELF and Unixware 7 with Native cc
  makefile.sggcc    =>  Silicon Graphics (gcc,
-                       creates libpng16.so.16.1.6.1)
+                       creates libpng16.so.16.1.6.2)
  makefile.sgi      =>  Silicon Graphics IRIX makefile (cc, creates static lib)
  makefile.solaris  =>  Solaris 2.X makefile (gcc,
-                       creates libpng16.so.16.1.6.1)
+                       creates libpng16.so.16.1.6.2)
  makefile.so9      =>  Solaris 9 makefile (gcc,
-                       creates libpng16.so.16.1.6.1)
+                       creates libpng16.so.16.1.6.2)
  makefile.std      =>  Generic UNIX makefile (cc, creates static libpng.a)
  makefile.sunos    =>  Sun makefile
  makefile.32sunu   =>  Sun Ultra 32-bit makefile
diff --git a/scripts/def.dfn b/scripts/def.dfn
index 5e1dc68..1415c2c 100644
--- a/scripts/def.dfn
+++ b/scripts/def.dfn
@@ -21,7 +21,7 @@
 PNG_DFN "OS2 CODE PRELOAD MOVEABLE DISCARDABLE"
 PNG_DFN ""
 PNG_DFN "EXPORTS"
-PNG_DFN ";Version 1.6.1"
+PNG_DFN ";Version 1.6.2"
 
 #define PNG_EXPORTA(ordinal, type, name, args, attributes)\
         PNG_DFN "@" SYMBOL_PREFIX "@@" name "@"
diff --git a/scripts/libpng-config-head.in b/scripts/libpng-config-head.in
index 9803d2e..7ab83ee 100755
--- a/scripts/libpng-config-head.in
+++ b/scripts/libpng-config-head.in
@@ -11,7 +11,7 @@
 
 # Modeled after libxml-config.
 
-version=1.6.1
+version=1.6.2
 prefix=""
 libdir=""
 libs=""
diff --git a/scripts/libpng.pc.in b/scripts/libpng.pc.in
index 9bdfd73..2fdeeb1 100644
--- a/scripts/libpng.pc.in
+++ b/scripts/libpng.pc.in
@@ -5,6 +5,6 @@
 
 Name: libpng
 Description: Loads and saves PNG files
-Version: 1.6.1
+Version: 1.6.2
 Libs: -L${libdir} -lpng16
 Cflags: -I${includedir}
diff --git a/scripts/makefile.cegcc b/scripts/makefile.cegcc
index 3912afe..d13012d 100644
--- a/scripts/makefile.cegcc
+++ b/scripts/makefile.cegcc
@@ -23,7 +23,7 @@
 
 VERMAJ = 1
 VERMIN = 6
-VERMIC = 1
+VERMIC = 2
 VER = $(VERMAJ).$(VERMIN).$(VERMIC)
 NAME = libpng
 PACKAGE = $(NAME)-$(VER)
diff --git a/scripts/makefile.linux b/scripts/makefile.linux
index 4e94ce9..3a13f0c 100644
--- a/scripts/makefile.linux
+++ b/scripts/makefile.linux
@@ -10,7 +10,7 @@
 # Library name:
 LIBNAME = libpng16
 PNGMAJ = 16
-RELEASE = 1
+RELEASE = 2
 
 # Shared library names:
 LIBSO=$(LIBNAME).so
diff --git a/scripts/makefile.msys b/scripts/makefile.msys
index 342c912..fc76184 100644
--- a/scripts/makefile.msys
+++ b/scripts/makefile.msys
@@ -18,7 +18,7 @@
 # Library name:
 LIBNAME = libpng16
 PNGMAJ = 16
-RELEASE = 1
+RELEASE = 2
 
 # Shared library names:
 LIBSO=$(LIBNAME).dll
diff --git a/scripts/makefile.ne12bsd b/scripts/makefile.ne12bsd
index 2313dd3..086decf 100644
--- a/scripts/makefile.ne12bsd
+++ b/scripts/makefile.ne12bsd
@@ -17,7 +17,7 @@
 
 LIB=	png16
 SHLIB_MAJOR=	0
-SHLIB_MINOR=	1.6.1
+SHLIB_MINOR=	1.6.2
 SRCS=	png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \
 	pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \
 	pngwtran.c pngmem.c pngerror.c pngpread.c
diff --git a/scripts/makefile.netbsd b/scripts/makefile.netbsd
index 41a2e9d..04ddf6d 100644
--- a/scripts/makefile.netbsd
+++ b/scripts/makefile.netbsd
@@ -17,7 +17,7 @@
 
 LIB=	png
 SHLIB_MAJOR=	16
-SHLIB_MINOR=	1.6.1
+SHLIB_MINOR=	1.6.2
 SRCS=	png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \
 	pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \
 	pngwtran.c pngmem.c pngerror.c pngpread.c
diff --git a/scripts/makefile.openbsd b/scripts/makefile.openbsd
index 2d63374..6026558 100644
--- a/scripts/makefile.openbsd
+++ b/scripts/makefile.openbsd
@@ -11,7 +11,7 @@
 MANDIR= ${PREFIX}/man/cat
 
 SHLIB_MAJOR=	16
-SHLIB_MINOR=	1.6.1
+SHLIB_MINOR=	1.6.2
 
 LIB=	png
 SRCS=	png.c pngerror.c pngget.c pngmem.c pngpread.c \
diff --git a/scripts/pnglibconf.h.prebuilt b/scripts/pnglibconf.h.prebuilt
index 1894e2d..16ad5c9 100644
--- a/scripts/pnglibconf.h.prebuilt
+++ b/scripts/pnglibconf.h.prebuilt
@@ -1,8 +1,8 @@
-/* libpng 1.6.1 STANDARD API DEFINITION */
+/* libpng 1.6.2 STANDARD API DEFINITION */
 
 /* pnglibconf.h - library build configuration */
 
-/* Libpng version 1.6.1 - March 28, 2013 */
+/* Libpng version 1.6.2 - April 25, 2013 */
 
 /* Copyright (c) 1998-2013 Glenn Randers-Pehrson */
 
diff --git a/scripts/symbols.def b/scripts/symbols.def
index d19022c..a99f164 100644
--- a/scripts/symbols.def
+++ b/scripts/symbols.def
@@ -1,4 +1,4 @@
-;Version 1.6.1
+;Version 1.6.2
 ;--------------------------------------------------------------
 ; LIBPNG symbol list as a Win32 DEF file
 ; Contains all the symbols that can be exported from libpng