Imported from libpng-1.2.1rc2.tar
diff --git a/ANNOUNCE b/ANNOUNCE
index 8269100..3d5da70 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,5 +1,5 @@
 
-Libpng 1.2.1rc1 - November 24, 2001
+Libpng 1.2.1rc2 - December 4, 2001
 
 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,6 +31,11 @@
   Updated makefile.sgi to recognize LIBPATH and INCPATH.
   Updated various makefiles so "make clean" does not remove previous major
     version of the shared library.
+version 1.2.1rc2 [December 4, 2001]
+  Added a pop/push operation to pngvcrd.c, to preserve Eflag.
+  Always allocate 256-entry internal palette, hist, and trans arrays, to
+    avoid out-of-bounds memory reference caused by invalid PNG datastreams.
+  Added a check for prefix_length > data_length in iCCP chunk handler.
 
 Send comments/corrections/commendations to
 png-implement@ccrc.wustl.edu or to randeg@alum.rpi.edu
diff --git a/CHANGES b/CHANGES
index a5d2556..c9b745d 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1007,6 +1007,11 @@
   Updated makefile.sgi to recognize LIBPATH and INCPATH.
   Updated various makefiles so "make clean" does not remove previous major
     version of the shared library.
+version 1.2.1rc2 [December 4, 2001]
+  Added a pop/push operation to pngvcrd.c, to preserve Eflag.
+  Always allocate 256-entry internal palette, hist, and trans arrays, to
+    avoid out-of-bounds memory reference caused by invalid PNG datastreams.
+  Added a check for prefix_length > data_length in iCCP chunk handler.
 
 Send comments/corrections/commendations to
 png-implement@ccrc.wustl.edu or to randeg@alum.rpi.edu
diff --git a/INSTALL b/INSTALL
index 0e9d176..a19c4db 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,5 +1,5 @@
 
-Installing libpng version 1.2.1rc1 - November 24, 2001
+Installing libpng version 1.2.1rc2 - December 4, 2001
 
 Before installing libpng, you must first install zlib.  zlib
 can usually be found wherever you got libpng.  zlib can be
@@ -10,7 +10,7 @@
 version of zlib that's installed.
 
 You can rename the directories that you downloaded (they
-might be called "libpng-1.2.1rc1" or "lpng109" and "zlib-1.1.3"
+might be called "libpng-1.2.1rc2" or "lpng109" and "zlib-1.1.3"
 or "zlib113") so that you have directories called "zlib" and "libpng".
 
 Your directory structure should look like this:
@@ -64,8 +64,8 @@
 include
 
  makefile.std      =>  Generic UNIX makefile (cc, creates static libpng.a)
- makefile.linux    =>  Linux/ELF makefile (gcc, creates libpng.so.3.1.2.1rc1)
- makefile.gcmmx    =>  Linux/ELF makefile (gcc, creates libpng.so.3.1.2.1rc1,
+ makefile.linux    =>  Linux/ELF makefile (gcc, creates libpng.so.3.1.2.1rc2)
+ makefile.gcmmx    =>  Linux/ELF makefile (gcc, creates libpng.so.3.1.2.1rc2,
                        uses assembler code tuned for Intel MMX platform)
  makefile.gcc      =>  Generic makefile (gcc, creates static libpng.a)
  makefile.knr      =>  Archaic UNIX Makefile that converts files with
@@ -83,10 +83,10 @@
  makefile.macosx   =>  MACOS X Makefile
  makefile.netbsd   =>  NetBSD/cc makefile, uses PNGGCCRD
  makefile.sgi      =>  Silicon Graphics IRIX makefile (cc, creates static lib)
- makefile.sggcc    =>  Silicon Graphics (gcc, creates libpng.so.3.1.2.1rc1)
+ makefile.sggcc    =>  Silicon Graphics (gcc, creates libpng.so.3.1.2.1rc2)
  makefile.sunos    =>  Sun makefile
- makefile.solaris  =>  Solaris 2.X makefile (gcc, creates libpng.so.3.1.2.1rc1)
- makefile.so9      =>  Solaris 9 makefile (gcc, creates libpng.so.3.1.2.1rc1)
+ makefile.solaris  =>  Solaris 2.X makefile (gcc, creates libpng.so.3.1.2.1rc2)
+ makefile.so9      =>  Solaris 9 makefile (gcc, creates libpng.so.3.1.2.1rc2)
  makefile.sco      =>  For SCO OSr5  ELF and Unixware 7 with Native cc
  makefile.mips     =>  MIPS makefile
  makefile.acorn    =>  Acorn makefile
diff --git a/KNOWNBUG b/KNOWNBUG
index a5f7a13..f2c93f3 100644
--- a/KNOWNBUG
+++ b/KNOWNBUG
@@ -1,5 +1,5 @@
 
-Known bugs in libpng version 1.2.1rc1
+Known bugs in libpng version 1.2.1rc2
 
 1. April 22, 2001: pnggccrd.c has been reported to crash on NetBSD when
    reading interlaced PNG files, when assembler code is enabled.
diff --git a/LICENSE b/LICENSE
index 66aec43..f554b53 100644
--- a/LICENSE
+++ b/LICENSE
@@ -8,7 +8,7 @@
 If you modify libpng you may insert additional notices immediately following
 this sentence.
 
-libpng versions 1.0.7, July 1, 2000, through 1.2.1rc1, November 24, 2001, are
+libpng versions 1.0.7, July 1, 2000, through 1.2.1rc2, December 4, 2001, are
 Copyright (c) 2000 Glenn Randers-Pehrson
 and are distributed according to the same disclaimer and license as libpng-1.0.6
 with the following individuals added to the list of Contributing Authors
@@ -99,4 +99,4 @@
 
 Glenn Randers-Pehrson
 randeg@alum.rpi.edu
-November 24, 2001
+December 4, 2001
diff --git a/README b/README
index 015ff09..5df3928 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-README for libpng 1.2.1rc1 - November 24, 2001 (shared library 2.1)
+README for libpng 1.2.1rc2 - December 4, 2001 (shared library 2.1)
 See the note about version numbers near the top of png.h
 
 See INSTALL for instructions on how to install libpng.
@@ -187,9 +187,9 @@
        descrip.mms      =>  VMS makefile for MMS or MMK
        makefile.std     =>  Generic UNIX makefile (cc, creates static libpng.a)
        makefile.linux   =>  Linux/ELF makefile
-                            (gcc, creates libpng.so.3.1.2.1rc1)
+                            (gcc, creates libpng.so.3.1.2.1rc2)
        makefile.gcmmx   =>  Linux/ELF makefile (gcc, creates
-                            libpng.so.3.1.2.1rc1, uses assembler code
+                            libpng.so.3.1.2.1rc2, uses assembler code
                             tuned for Intel MMX platform)
        makefile.gcc     =>  Generic makefile (gcc, creates static libpng.a)
        makefile.knr     =>  Archaic UNIX Makefile that converts files with
@@ -207,12 +207,12 @@
        makefile.macosx  =>  MACOS X Makefile
        makefile.netbsd  =>  NetBSD/cc makefile, uses PNGGCCRD
        makefile.sgi     =>  Silicon Graphics IRIX (cc, creates static lib)
-       makefile.sggcc   =>  Silicon Graphics (gcc, creates libpng.so.3.1.2.1rc1)
+       makefile.sggcc   =>  Silicon Graphics (gcc, creates libpng.so.3.1.2.1rc2)
        makefile.sunos   =>  Sun makefile
        makefile.solaris =>  Solaris 2.X makefile
-                            (gcc, creates libpng.so.3.1.2.1rc1)
+                            (gcc, creates libpng.so.3.1.2.1rc2)
        makefile.so9     =>  Solaris 9 makefile
-                            (gcc, creates libpng.so.3.1.2.1rc1)
+                            (gcc, creates libpng.so.3.1.2.1rc2)
        makefile.sco     =>  For SCO OSr5  ELF and Unixware 7 with Native cc
        makefile.mips    =>  MIPS makefile
        makefile.acorn   =>  Acorn makefile
diff --git a/Y2KINFO b/Y2KINFO
index 2e95a5f..c95c51c 100644
--- a/Y2KINFO
+++ b/Y2KINFO
@@ -1,13 +1,13 @@
    Y2K compliance in libpng:
    =========================
 
-      November 24, 2001
+      December 4, 2001
 
       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.2.1rc1 are Y2K compliant.  It is my belief that earlier
+      upward through 1.2.1rc2 are Y2K compliant.  It is my belief that earlier
       versions were also Y2K compliant.
 
       Libpng only has three year fields.  One is a 2-byte unsigned integer
diff --git a/configure b/configure
index 22dcb21..0359b53 100755
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 echo "
-  There is no \"configure\" script for Libpng-1.2.1rc1.  Instead, please
+  There is no \"configure\" script for Libpng-1.2.1rc2.  Instead, please
   copy the appropriate makefile for your system from the \"scripts\"
   directory.  Read the INSTALL file for more details.
 "
diff --git a/libpng.3 b/libpng.3
index c8f195f..60f1bff 100644
--- a/libpng.3
+++ b/libpng.3
@@ -1,6 +1,6 @@
-.TH LIBPNG 3 "November 24, 2001"
+.TH LIBPNG 3 "December 4, 2001"
 .SH NAME
-libpng \- Portable Network Graphics (PNG) Reference Library 1.2.1rc1
+libpng \- Portable Network Graphics (PNG) Reference Library 1.2.1rc2
 .SH SYNOPSIS
 \fI\fB
 
@@ -787,7 +787,7 @@
 .SH LIBPNG.TXT
 libpng.txt - A description on how to use and modify libpng
 
- libpng version 1.2.1rc1 - November 24, 2001
+ libpng version 1.2.1rc2 - December 4, 2001
  Updated and distributed by Glenn Randers-Pehrson
  <randeg@alum.rpi.edu>
  Copyright (c) 1998-2001 Glenn Randers-Pehrson
@@ -3635,13 +3635,13 @@
 
 .SH IX. Y2K Compliance in libpng
 
-November 24, 2001
+December 4, 2001
 
 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.2.1rc1 are Y2K compliant.  It is my belief that earlier
+upward through 1.2.1rc2 are Y2K compliant.  It is my belief that earlier
 versions were also Y2K compliant.
 
 Libpng only has three year fields.  One is a 2-byte unsigned integer that
@@ -3762,7 +3762,8 @@
  1.2.0rc1             3    10200  3.1.2.0rc1
  1.2.0                3    10200  3.1.2.0
  1.2.1beta-4          3    10201  3.1.2.1beta1-4
- 1.2.1rc1             3    10201  3.1.2.1rc1
+ 1.2.1rc1-2           3    10201  3.1.2.1rc1-2
+ 1.2.1                3    10201  3.1.2.1
 
 Henceforth the source version will match the shared-library minor
 and patch numbers; the shared-library major version number will be
@@ -3820,7 +3821,7 @@
 
 Thanks to Frank J. T. Wojcik for helping with the documentation.
 
-Libpng version 1.2.1rc1 - November 24, 2001:
+Libpng version 1.2.1rc2 - December 4, 2001:
 Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
 Currently maintained by Glenn Randers-Pehrson (randeg@alum.rpi.edu).
 
@@ -3837,7 +3838,7 @@
 If you modify libpng you may insert additional notices immediately following
 this sentence.
 
-libpng versions 1.0.7, July 1, 2000, through  1.2.1rc1, November 24, 2001, are
+libpng versions 1.0.7, July 1, 2000, through  1.2.1rc2, December 4, 2001, are
 Copyright (c) 2000-2001 Glenn Randers-Pehrson, and are
 distributed according to the same disclaimer and license as libpng-1.0.6
 with the following individuals added to the list of Contributing Authors
@@ -3929,7 +3930,7 @@
 
 Glenn Randers-Pehrson
 randeg@alum.rpi.edu
-November 24, 2001
+December 4, 2001
 
 .\" end of man page
 
diff --git a/libpng.txt b/libpng.txt
index b9e57e7..cb4495f 100644
--- a/libpng.txt
+++ b/libpng.txt
@@ -1,6 +1,6 @@
 libpng.txt - A description on how to use and modify libpng
 
- libpng version 1.2.1rc1 - November 24, 2001
+ libpng version 1.2.1rc2 - December 4, 2001
  Updated and distributed by Glenn Randers-Pehrson
  <randeg@alum.rpi.edu>
  Copyright (c) 1998-2001 Glenn Randers-Pehrson
@@ -2848,13 +2848,13 @@
 
 IX. Y2K Compliance in libpng
 
-November 24, 2001
+December 4, 2001
 
 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.2.1rc1 are Y2K compliant.  It is my belief that earlier
+upward through 1.2.1rc2 are Y2K compliant.  It is my belief that earlier
 versions were also Y2K compliant.
 
 Libpng only has three year fields.  One is a 2-byte unsigned integer that
diff --git a/libpngpf.3 b/libpngpf.3
index 8340d03..269a4cf 100644
--- a/libpngpf.3
+++ b/libpngpf.3
@@ -1,6 +1,6 @@
-.TH LIBPNGPF 3 "November 24, 2001"
+.TH LIBPNGPF 3 "December 4, 2001"
 .SH NAME
-libpng \- Portable Network Graphics (PNG) Reference Library 1.2.1rc1
+libpng \- Portable Network Graphics (PNG) Reference Library 1.2.1rc2
 (private functions)
 .SH SYNOPSIS
 \fB#include <png.h>\fP
diff --git a/png.5 b/png.5
index f1d6c49..00e1a37 100644
--- a/png.5
+++ b/png.5
@@ -1,4 +1,4 @@
-.TH PNG 5 "November 24, 2001"
+.TH PNG 5 "December 4, 2001"
 .SH NAME
 png \- Portable Network Graphics (PNG) format
 .SH DESCRIPTION
diff --git a/png.c b/png.c
index 2ade62a..428f552 100644
--- a/png.c
+++ b/png.c
@@ -1,7 +1,7 @@
 
 /* png.c - location for general purpose libpng functions
  *
- * libpng version 1.2.1rc1 - November 24, 2001
+ * libpng version 1.2.1rc2 - December 4, 2001
  * Copyright (c) 1998-2001 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.)
@@ -13,14 +13,14 @@
 #include "png.h"
 
 /* Generate a compiler error if there is an old png.h in the search path. */
-typedef version_1_2_1rc1 Your_png_h_is_not_version_1_2_1rc1;
+typedef version_1_2_1rc2 Your_png_h_is_not_version_1_2_1rc2;
 
 /* Version information for C files.  This had better match the version
  * string defined in png.h.  */
 
 #ifdef PNG_USE_GLOBAL_ARRAYS
 /* png_libpng_ver was changed to a function in version 1.0.5c */
-const char png_libpng_ver[18] = "1.2.1rc1";
+const char png_libpng_ver[18] = "1.2.1rc2";
 
 /* png_sig was changed to a function in version 1.0.5c */
 /* Place to hold the signature string for a PNG file. */
@@ -645,7 +645,7 @@
 png_get_copyright(png_structp png_ptr)
 {
    if (png_ptr != NULL || png_ptr == NULL)  /* silence compiler warning */
-   return ((png_charp) "\n libpng version 1.2.1rc1 - November 24, 2001\n\
+   return ((png_charp) "\n libpng version 1.2.1rc2 - December 4, 2001\n\
    Copyright (c) 1998-2001 Glenn Randers-Pehrson\n\
    Copyright (c) 1996, 1997 Andreas Dilger\n\
    Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n");
@@ -663,8 +663,8 @@
 {
    /* Version of *.c files used when building libpng */
    if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
-      return((png_charp) "1.2.1rc1");
-   return((png_charp) "1.2.1rc1");
+      return((png_charp) "1.2.1rc2");
+   return((png_charp) "1.2.1rc2");
 }
 
 png_charp PNGAPI
diff --git a/png.h b/png.h
index 07ee520..7dea7c8 100644
--- a/png.h
+++ b/png.h
@@ -1,7 +1,7 @@
 
 /* png.h - header file for PNG reference library
  *
- * libpng version 1.2.1rc1 - November 24, 2001
+ * libpng version 1.2.1rc2 - December 4, 2001
  * Copyright (c) 1998-2001 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.)
@@ -9,7 +9,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.2.1rc1 - November 24, 2001: Glenn
+ *  libpng versions 0.97, January 1998, through 1.2.1rc2 - December 4, 2001: Glenn
  *  See also "Contributing Authors", below.
  *
  * Note about libpng version numbers:
@@ -79,7 +79,8 @@
  *    1.2.0rc1                 3    10200  3.1.2.0rc1
  *    1.2.0                    3    10200  3.1.2.0
  *    1.2.1beta1-4             3    10201  3.1.2.1beta1-4
- *    1.2.1rc1                 3    10201  3.1.2.1rc1
+ *    1.2.1rc1-2               3    10201  3.1.2.1rc1-2
+ *    1.2.1                    3    10201  3.1.2.1
  *
  *    Henceforth the source version will match the shared-library major
  *    and minor numbers; the shared-library major version number will be
@@ -109,7 +110,7 @@
  * If you modify libpng you may insert additional notices immediately following
  * this sentence.
  *
- * libpng versions 1.0.7, July 1, 2000, through  1.2.1rc1, November 24, 2001, are
+ * libpng versions 1.0.7, July 1, 2000, through  1.2.1rc2, December 4, 2001, are
  * Copyright (c) 2000, 2001 Glenn Randers-Pehrson, and are
  * distributed according to the same disclaimer and license as libpng-1.0.6
  * with the following individuals added to the list of Contributing Authors
@@ -214,13 +215,13 @@
  * Y2K compliance in libpng:
  * =========================
  *
- *    November 24, 2001
+ *    December 4, 2001
  *
  *    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.2.1rc1 are Y2K compliant.  It is my belief that earlier
+ *    upward through 1.2.1rc2 are Y2K compliant.  It is my belief that earlier
  *    versions were also Y2K compliant.
  *
  *    Libpng only has three year fields.  One is a 2-byte unsigned integer
@@ -276,7 +277,7 @@
  */
 
 /* Version information for png.h - this should match the version in png.c */
-#define PNG_LIBPNG_VER_STRING "1.2.1rc1"
+#define PNG_LIBPNG_VER_STRING "1.2.1rc2"
 
 #define PNG_LIBPNG_VER_SONUM   3
 #define PNG_LIBPNG_VER_DLLNUM  %DLLNUM%
@@ -288,7 +289,7 @@
 /* This should match the numeric part of the final component of
  * PNG_LIBPNG_VER_STRING, omitting any leading zero: */
 
-#define PNG_LIBPNG_VER_BUILD  1
+#define PNG_LIBPNG_VER_BUILD  2
 
 #define PNG_LIBPNG_BUILD_ALPHA    1
 #define PNG_LIBPNG_BUILD_BETA     2
@@ -1252,9 +1253,9 @@
 
 
 /* This prevents a compiler error in png_get_copyright() in png.c if png.c
-   and png.h are both at version 1.2.1rc1
+   and png.h are both at version 1.2.1rc2
  */
-typedef png_structp version_1_2_1rc1;
+typedef png_structp version_1_2_1rc2;
 
 typedef png_struct FAR * FAR * png_structpp;
 
@@ -2371,7 +2372,7 @@
 /* Maintainer: Put new public prototypes here ^, in libpng.3, and project defs */
 
 #define PNG_HEADER_VERSION_STRING \
-   " libpng version 1.2.1rc1 - November 24, 2001 (header)\n"
+   " libpng version 1.2.1rc2 - December 4, 2001 (header)\n"
 
 #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
 /* With these routines we avoid an integer divide, which will be slower on
diff --git a/pngasmrd.h b/pngasmrd.h
index 829c325..47c7a63 100644
--- a/pngasmrd.h
+++ b/pngasmrd.h
@@ -1,6 +1,6 @@
 /* pngasmrd.h - assembler version of utilities to read a PNG file
  *
- * libpng 1.2.1rc1 - November 24, 2001
+ * libpng 1.2.1rc2 - December 4, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 2001 Glenn Randers-Pehrson
  *
diff --git a/pngconf.h b/pngconf.h
index 95d08a3..24b61db 100644
--- a/pngconf.h
+++ b/pngconf.h
@@ -1,6 +1,6 @@
 /* pngconf.h - machine configurable file for libpng
  *
- * libpng 1.2.1rc1 - November 24, 2001
+ * libpng 1.2.1rc2 - December 4, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngerror.c b/pngerror.c
index 3a13117..d2fb4d7 100644
--- a/pngerror.c
+++ b/pngerror.c
@@ -1,7 +1,7 @@
 
 /* pngerror.c - stub functions for i/o and memory allocation
  *
- * libpng 1.2.1rc1 - November 24, 2001
+ * libpng 1.2.1rc2 - December 4, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pnggccrd.c b/pnggccrd.c
index 5c4e317..a1ad71a 100644
--- a/pnggccrd.c
+++ b/pnggccrd.c
@@ -6,7 +6,7 @@
  *     and http://www.intel.com/drg/pentiumII/appnotes/923/923.htm
  *     for Intel's performance analysis of the MMX vs. non-MMX code.
  *
- * libpng version 1.2.1rc1 - November 24, 2001
+ * libpng version 1.2.1rc2 - December 4, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * Copyright (c) 1998, Intel Corporation
diff --git a/pngget.c b/pngget.c
index 5d193fb..501125f 100644
--- a/pngget.c
+++ b/pngget.c
@@ -1,7 +1,7 @@
 
 /* pngget.c - retrieval of values from info struct
  *
- * libpng 1.2.1rc1 - November 24, 2001
+ * libpng 1.2.1rc2 - December 4, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngmem.c b/pngmem.c
index 37a7510..0f06a59 100644
--- a/pngmem.c
+++ b/pngmem.c
@@ -1,7 +1,7 @@
 
 /* pngmem.c - stub functions for memory allocation
  *
- * libpng 1.2.1rc1 - November 24, 2001
+ * libpng 1.2.1rc2 - December 4, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngpread.c b/pngpread.c
index 88483ba..a444abe 100644
--- a/pngpread.c
+++ b/pngpread.c
@@ -1,7 +1,7 @@
 
 /* pngpread.c - read a png file in push mode
  *
- * libpng 1.2.1rc1 - November 24, 2001
+ * libpng 1.2.1rc2 - December 4, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngread.c b/pngread.c
index 0e1f116..27b8cfa 100644
--- a/pngread.c
+++ b/pngread.c
@@ -1,7 +1,7 @@
 
 /* pngread.c - read a PNG file
  *
- * libpng 1.2.1rc1 - November 24, 2001
+ * libpng 1.2.1rc2 - December 4, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -767,7 +767,7 @@
  * not called png_set_interlace_handling(), the display_row buffer will
  * be ignored, so pass NULL to it.
  *
- * [*] png_handle_alpha() does not exist yet, as of libpng version 1.2.1rc1
+ * [*] png_handle_alpha() does not exist yet, as of libpng version 1.2.1rc2
  */
 
 void PNGAPI
@@ -816,7 +816,7 @@
  * only call this function once.  If you desire to have an image for
  * each pass of a interlaced image, use png_read_rows() instead.
  *
- * [*] png_handle_alpha() does not exist yet, as of libpng version 1.2.1rc1
+ * [*] png_handle_alpha() does not exist yet, as of libpng version 1.2.1rc2
  */
 void PNGAPI
 png_read_image(png_structp png_ptr, png_bytepp image)
diff --git a/pngrio.c b/pngrio.c
index cb211d8..629ab05 100644
--- a/pngrio.c
+++ b/pngrio.c
@@ -1,7 +1,7 @@
 
 /* pngrio.c - functions for data input
  *
- * libpng 1.2.1rc1 - November 24, 2001
+ * libpng 1.2.1rc2 - December 4, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngrtran.c b/pngrtran.c
index b9b6bdb..0b7dd5a 100644
--- a/pngrtran.c
+++ b/pngrtran.c
@@ -1,7 +1,7 @@
 
 /* pngrtran.c - transforms the data in a row for PNG readers
  *
- * libpng 1.2.1rc1 - November 24, 2001
+ * libpng 1.2.1rc2 - December 4, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngrutil.c b/pngrutil.c
index b795dc4..ecb7a1b 100644
--- a/pngrutil.c
+++ b/pngrutil.c
@@ -1,7 +1,7 @@
 
 /* pngrutil.c - utilities to read a PNG file
  *
- * libpng 1.2.1rc1 - November 24, 2001
+ * libpng 1.2.1rc2 - December 4, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -1029,7 +1029,7 @@
 
    profile_length = data_length - prefix_length;
 
-   if ( profile_length < 4)
+   if ( prefix_length > data_length || profile_length < 4)
    {
       png_free(png_ptr, chunkdata);
       png_warning(png_ptr, "Profile size field missing from iCCP chunk");
diff --git a/pngset.c b/pngset.c
index 342c592..41eb028 100644
--- a/pngset.c
+++ b/pngset.c
@@ -1,7 +1,7 @@
 
 /* pngset.c - storage of image information into info struct
  *
- * libpng 1.2.1rc1 - November 24, 2001
+ * libpng 1.2.1rc2 - December 4, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -152,8 +152,9 @@
 #ifdef PNG_FREE_ME_SUPPORTED
    png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
 #endif
+   /* Changed from info->num_palette to 256 in version 1.2.1 */
    png_ptr->hist = (png_uint_16p)png_malloc(png_ptr,
-      (png_uint_32)(info_ptr->num_palette * sizeof (png_uint_16)));
+      (png_uint_32)(256 * sizeof (png_uint_16)));
 
    for (i = 0; i < info_ptr->num_palette; i++)
        png_ptr->hist[i] = hist[i];
@@ -410,7 +411,9 @@
 #ifdef PNG_FREE_ME_SUPPORTED
    png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
 #endif
-   png_ptr->palette = (png_colorp)png_zalloc(png_ptr, (uInt)num_palette,
+   /* Changed in libpng-1.2.1 to allocate 256 instead of num_palette entries,
+      in case of an invalid PNG file that has too-large sample values. */
+   png_ptr->palette = (png_colorp)png_zalloc(png_ptr, (uInt)256,
       sizeof (png_color));
    png_memcpy(png_ptr->palette, palette, num_palette * sizeof (png_color));
    info_ptr->palette = png_ptr->palette;
@@ -740,8 +743,9 @@
 #ifdef PNG_FREE_ME_SUPPORTED
        png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
 #endif
+       /* Changed from num_trans to 256 in version 1.2.1 */
        png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
-           (png_uint_32)num_trans);
+           (png_uint_32)256);
        png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
 #ifdef PNG_FREE_ME_SUPPORTED
        info_ptr->free_me |= PNG_FREE_TRNS;
diff --git a/pngtest.c b/pngtest.c
index 3a68603..d18d568 100644
--- a/pngtest.c
+++ b/pngtest.c
@@ -1,7 +1,7 @@
 
 /* pngtest.c - a simple test program to test libpng
  *
- * libpng 1.2.1rc1 - November 24, 2001
+ * libpng 1.2.1rc2 - December 4, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -1512,4 +1512,4 @@
 }
 
 /* Generate a compiler error if there is an old png.h in the search path. */
-typedef version_1_2_1rc1 your_png_h_is_not_version_1_2_1rc1;
+typedef version_1_2_1rc2 your_png_h_is_not_version_1_2_1rc2;
diff --git a/pngtrans.c b/pngtrans.c
index f1ccd66..232e2cd 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)
  *
- * libpng 1.2.1rc1 - November 24, 2001
+ * libpng 1.2.1rc2 - December 4, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngvcrd.c b/pngvcrd.c
index ed428d6..281475f 100644
--- a/pngvcrd.c
+++ b/pngvcrd.c
@@ -2,7 +2,7 @@
  *
  * For Intel x86 CPU and Microsoft Visual C++ compiler
  *
- * libpng 1.2.1rc1 - November 24, 2001
+ * libpng version 1.2.1rc2 - December 4, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * Copyright (c) 1998, Intel Corporation
@@ -39,6 +39,7 @@
     push ebx          //CPUID will trash these
     push ecx
     push edx
+
     pushfd            //Save Eflag to stack
     pop eax           //Get Eflag from stack into eax
     mov ecx, eax      //Make another copy of Eflag in ecx
@@ -48,6 +49,8 @@
     popfd             //Restored modified value back to Eflag reg
     pushfd            //Save Eflag to stack
     pop eax           //Get Eflag from stack
+    push ecx          // save original Eflag to stack
+    popfd             // restore original Eflag
     xor eax, ecx      //Compare the new Eflag with the original Eflag
     jz NOT_SUPPORTED  //If the same, CPUID instruction is not supported,
                       //skip following instructions and jump to
diff --git a/pngwio.c b/pngwio.c
index 612c729..c183295 100644
--- a/pngwio.c
+++ b/pngwio.c
@@ -1,7 +1,7 @@
 
 /* pngwio.c - functions for data output
  *
- * libpng 1.2.1rc1 - November 24, 2001
+ * libpng 1.2.1rc2 - December 4, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngwrite.c b/pngwrite.c
index 3d4cfcc..3f03527 100644
--- a/pngwrite.c
+++ b/pngwrite.c
@@ -1,7 +1,7 @@
 
 /* pngwrite.c - general routines to write a PNG file
  *
- * libpng 1.2.1rc1 - November 24, 2001
+ * libpng 1.2.1rc2 - December 4, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngwtran.c b/pngwtran.c
index 52ae4a8..c26d3c8 100644
--- a/pngwtran.c
+++ b/pngwtran.c
@@ -1,7 +1,7 @@
 
 /* pngwtran.c - transforms the data in a row for PNG writers
  *
- * libpng 1.2.1rc1 - November 24, 2001
+ * libpng 1.2.1rc2 - December 4, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngwutil.c b/pngwutil.c
index f971303..56ee12e 100644
--- a/pngwutil.c
+++ b/pngwutil.c
@@ -1,7 +1,7 @@
 
 /* pngwutil.c - utilities to write a PNG file
  *
- * libpng 1.2.1rc1 - November 24, 2001
+ * libpng 1.2.1rc2 - December 4, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/projects/msvc/README.txt b/projects/msvc/README.txt
index d8ab6b2..1b4649c 100644
--- a/projects/msvc/README.txt
+++ b/projects/msvc/README.txt
@@ -1,5 +1,5 @@
 Microsoft Developer Studio Build File, Format Version 6.00 for
-libpng 1.2.1rc1 (November 24, 2001) and zlib
+libpng 1.2.1rc2 (December 4, 2001) and zlib
 
 Copyright (C) 2000 Simon-Pierre Cadieux
 For conditions of distribution and use, see copyright notice in png.h
diff --git a/projects/msvc/png32ms.def b/projects/msvc/png32ms.def
index 4f57e82..9d5d5a5 100644
--- a/projects/msvc/png32ms.def
+++ b/projects/msvc/png32ms.def
@@ -6,7 +6,7 @@
 DESCRIPTION "PNG image compression library for Windows"
 
 EXPORTS
-;Version 1.2.1rc1
+;Version 1.2.1rc2
   png_build_grayscale_palette  @1
   png_check_sig        @2
   png_chunk_error      @3
diff --git a/projects/netware.txt b/projects/netware.txt
index 16a6b1a..e277c61 100644
--- a/projects/netware.txt
+++ b/projects/netware.txt
@@ -1,6 +1,6 @@
 A set of project files is available for Netware.  Get
-libpng-1.2.1rc1-project-netware.zip from a libpng distribution
+libpng-1.2.1rc2-project-netware.zip from a libpng distribution
 site such as http://libpng.sourceforge.net
 
 Put the zip file in this directory (projects) and then run
-"unzip -a libpng-1.2.1rc1-project-netware.zip"
+"unzip -a libpng-1.2.1rc2-project-netware.zip"
diff --git a/projects/wince.txt b/projects/wince.txt
index c93547e..7fa90bb 100644
--- a/projects/wince.txt
+++ b/projects/wince.txt
@@ -1,6 +1,6 @@
 A set of project files is available for WinCE.  Get
-libpng-1.2.1rc1-project-wince.zip from a libpng distribution
+libpng-1.2.1rc2-project-wince.zip from a libpng distribution
 site such as http://libpng.sourceforge.net
 
 Put the zip file in this directory (projects) and then run
-"unzip -a libpng-1.2.1rc1-project-wince.zip"
+"unzip -a libpng-1.2.1rc2-project-wince.zip"
diff --git a/scripts/makefile.aix b/scripts/makefile.aix
index 4afecd5..f882bf7 100644
--- a/scripts/makefile.aix
+++ b/scripts/makefile.aix
@@ -18,7 +18,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.1rc1
+PNGMIN = 1.2.1rc2
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 prefix=/usr/local
diff --git a/scripts/makefile.beos b/scripts/makefile.beos
index d194198..045ad9a 100644
--- a/scripts/makefile.beos
+++ b/scripts/makefile.beos
@@ -13,7 +13,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.1rc1
+PNGMIN = 1.2.1rc2
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 ALIGN=
diff --git a/scripts/makefile.cygwin b/scripts/makefile.cygwin
index e739fdd..2267d65 100644
--- a/scripts/makefile.cygwin
+++ b/scripts/makefile.cygwin
@@ -39,7 +39,7 @@
 # have to change it.
 PNGMAJ = 3
 #PNGDLL = $3
-PNGMIN = 1.2.1rc1
+PNGMIN = 1.2.1rc2
 PNGMIN_BASE = 1.2.1
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
diff --git a/scripts/makefile.darwin b/scripts/makefile.darwin
index 2d08ab9..c6de767 100644
--- a/scripts/makefile.darwin
+++ b/scripts/makefile.darwin
@@ -24,7 +24,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.1rc1
+PNGMIN = 1.2.1rc2
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 INCPATH=$(prefix)/include
diff --git a/scripts/makefile.dec b/scripts/makefile.dec
index b53bd98..6abb4a3 100644
--- a/scripts/makefile.dec
+++ b/scripts/makefile.dec
@@ -17,7 +17,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.1rc1
+PNGMIN = 1.2.1rc2
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 CC=cc
diff --git a/scripts/makefile.gcmmx b/scripts/makefile.gcmmx
index 289f1c3..51e0d57 100644
--- a/scripts/makefile.gcmmx
+++ b/scripts/makefile.gcmmx
@@ -55,7 +55,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.1rc1
+PNGMIN = 1.2.1rc2
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 INCPATH=$(prefix)/include
diff --git a/scripts/makefile.hpgcc b/scripts/makefile.hpgcc
index 0dfd53a..9fac429 100644
--- a/scripts/makefile.hpgcc
+++ b/scripts/makefile.hpgcc
@@ -34,7 +34,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.1rc1
+PNGMIN = 1.2.1rc2
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 INCPATH=$(prefix)/include
diff --git a/scripts/makefile.hpux b/scripts/makefile.hpux
index fd122f3..2a6e43c 100644
--- a/scripts/makefile.hpux
+++ b/scripts/makefile.hpux
@@ -19,7 +19,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.1rc1
+PNGMIN = 1.2.1rc2
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 # where make install puts libpng.a and png.h
diff --git a/scripts/makefile.linux b/scripts/makefile.linux
index a4966d7..e54657a 100644
--- a/scripts/makefile.linux
+++ b/scripts/makefile.linux
@@ -34,7 +34,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.1rc1
+PNGMIN = 1.2.1rc2
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 INCPATH=$(prefix)/include
diff --git a/scripts/makefile.macosx b/scripts/makefile.macosx
index b694d04..525311d 100644
--- a/scripts/makefile.macosx
+++ b/scripts/makefile.macosx
@@ -19,7 +19,7 @@
 LDSHARED=cc -lz -dynamiclib -compatibility_version $(VER) -current_version $(VER)
 
 PNGMAJ = 3
-PNGMIN = 1.2.1rc1
+PNGMIN = 1.2.1rc2
 VER = $(PNGMAJ).$(PNGMIN)
 SHAREDLIB=libpng
 SHAREDLIB_POSTFIX=dylib
diff --git a/scripts/makefile.netbsd b/scripts/makefile.netbsd
index f7da259..c3f944b 100644
--- a/scripts/makefile.netbsd
+++ b/scripts/makefile.netbsd
@@ -11,7 +11,7 @@
 
 LIB=png
 SHLIB_MAJOR= 3
-SHLIB_MINOR= 1.2.1rc1
+SHLIB_MINOR= 1.2.1rc2
 SRCS=	pnggccrd.c 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.sco b/scripts/makefile.sco
index 92245eb..abe8b38 100644
--- a/scripts/makefile.sco
+++ b/scripts/makefile.sco
@@ -25,7 +25,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.1rc1
+PNGMIN = 1.2.1rc2
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 INCPATH=$(prefix)/include
diff --git a/scripts/makefile.sggcc b/scripts/makefile.sggcc
index 2b9193b..f0c2bed 100644
--- a/scripts/makefile.sggcc
+++ b/scripts/makefile.sggcc
@@ -22,7 +22,7 @@
 LDFLAGS=$(ABI) -L. -L$(ZLIBLIB) -lpng -lz -lm
 LDSHARED=CC $(ABI) -shared
 
-VER=1.2.1rc1
+VER=1.2.1rc2
 # See "man dso" for info about shared objects
 SONUM=3
 LIBS=libpng.so.$(SONUM).$(VER)
diff --git a/scripts/makefile.sgi b/scripts/makefile.sgi
index 7d7aa3f..d777ffc 100644
--- a/scripts/makefile.sgi
+++ b/scripts/makefile.sgi
@@ -27,7 +27,7 @@
 LDFLAGS=$(ABI) -L. -L$(ZLIBLIB) -lpng -lz -lm
 LDSHARED=cc $(ABI) -shared
 
-VER=1.2.1rc1
+VER=1.2.1rc2
 # See "man dso" for info about shared objects
 SONUM=3
 SHAREDLIB=libpng.so
diff --git a/scripts/makefile.so9 b/scripts/makefile.so9
index 3b51fd9..9b57324 100644
--- a/scripts/makefile.so9
+++ b/scripts/makefile.so9
@@ -35,7 +35,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.1rc1
+PNGMIN = 1.2.1rc2
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 INCPATH=$(prefix)/include
diff --git a/scripts/makefile.solaris b/scripts/makefile.solaris
index 1ba8245..235e110 100644
--- a/scripts/makefile.solaris
+++ b/scripts/makefile.solaris
@@ -31,7 +31,7 @@
 # read libpng.txt or png.h to see why PNGMAJ is 3.  You should not
 # have to change it.
 PNGMAJ = 3
-PNGMIN = 1.2.1rc1
+PNGMIN = 1.2.1rc2
 PNGVER = $(PNGMAJ).$(PNGMIN)
 
 INCPATH=$(prefix)/include
diff --git a/scripts/pngdef.pas b/scripts/pngdef.pas
index 0cc41a5..198a1d6 100644
--- a/scripts/pngdef.pas
+++ b/scripts/pngdef.pas
@@ -7,7 +7,7 @@
 interface
 
 const
-  PNG_LIBPNG_VER_STRING = '1.2.1rc1';
+  PNG_LIBPNG_VER_STRING = '1.2.1rc2';
   PNG_LIBPNG_VER        =  10201;
 
 type
diff --git a/scripts/pngos2.def b/scripts/pngos2.def
index 349d83f..95e7450 100644
--- a/scripts/pngos2.def
+++ b/scripts/pngos2.def
@@ -2,7 +2,7 @@
 ; PNG.LIB module definition file for OS/2
 ;----------------------------------------
 
-; Version 1.2.1rc1
+; Version 1.2.1rc2
 
 LIBRARY		PNG
 DESCRIPTION	"PNG image compression library for OS/2"