 * ChangeLog (oldest first):
 *
 * Started by Alexander Lehmann <alex@hal.rhein-main.de> and subsequently
 * extended by people as listed below.
 *
 *   AL   -  Alexander Lehmann
 *   AED  -  Andreas Dilger
 *   BB   -  Ben Beasley (Fedora Linux)
 *   GRP  -  Glenn Randers-Pehrson
 *   GRR  -  Greg Roelofs
 *   JB   -  John Bowler
 *   TGL  -  Tom Lane
 *
 * 19950223 AL:  fixed wrong magic numbers
 *               ["version 1.1"]
 *               ---------------
 * 19950313 AL:  CRC code from PNG spec; compiles on memory-impaired PCs now;
 *               check for IHDR/IEND chunks
 *               ["version 1.2"]
 *               ---------------
 * 19950325 GRP: rewrote magic-number-checking and moved it to PNG_check_magic()
 *               ["version 1.3"]
 *               ---------------
 * 19950327 AL:  fixed CRC code for 64-bit; -t switch; unsigned char vs. char
 *               pointer changes
 *               ["version 1.4"]
 *               ---------------
 * 19960601 AL:  check for data after IEND chunk
 *               ["version 1.5"]
 *               ---------------
 * 19950601 GRR: reformatted; print tEXt and zTXt keywords; added usage
 * 19950601 GRR: released version 1.6, a.k.a. pngcheck-grr1.c
 *               --------------------------------------------
 * 19950607 GRR: print image info (IHDR) and tIME; enable EMX wildcards
 * 19950615 GRR: released version 1.61, a.k.a. pngcheck-grr2.c
 *               ---------------------------------------------
 * 19950731 AL:  check for control chars; check for MacBinary header; new
 *               force option
 * 19950731 AL:  released version 1.7
 *               --------------------
 * 19950827 AL:  merged Greg's 1.61 changes: print IHDR and tIME contents,
 *               call emx wildcard function
 * 19950827 AL:  released version 1.8
 *               --------------------
 * 19950904 GRR: added brackets on keyword error messages to distinguish from
 *               keyword text
 * 19950904 GRR: released version 1.81
 *               ---------------------
 * 19951121 AED: re-ordered internal chunk checking in pngcheck().
 *               Now decodes most of the known chunk types to check for invalid
 *               contents (except IDAT and zTXt).  Information is printed
 *               about the contents of known chunks, and unknown chunks have
 *               their chunk name flags decoded.  Also checks chunk ordering.
 * 19951121 AED: released version 1.9
 *               --------------------
 * 19951126 AED: minor bug fixes and nicening of the output.  Checks for
 *               valid cHRM contents per Chris Lilley's recommendation.
 * 19951126 AED: released version 1.91
 *               ---------------------
 * 19951204 AED: minor bug in cHRM error output fixed
 * 19960105 AED: added -q flaq to output a message only if an error occurs
 * 19960105 AED: released version 1.92
 *               ---------------------
 * 19960119 AED: added ability to parse multiple options with a single '-';
 *               changed tIME output to be in RFC 1123 format
 * 19960306 AED: released version 1.93
 *               ---------------------
 * 19960517 GRR: fixed obvious(?) fprintf error; fixed multiple-tIME error msg
 * 19960517 GRR: released version 1.94
 *               ---------------------
 * 19960521 AL:  fixed two tRNS errors reported by someone from W3C (whose name
 *               I currently don't remember) (complained about missing palette
 *               in greyscale images, missing breaks in case statement); avoid
 *               reference to undefined array entry with out of range ityp
 * 19960521 AL:  released version 1.95
 *               ---------------------
 * 19960605 AED: removed extra linefeed from cHRM output when not verbose;
 *               added test to see if sBIT contents are valid;
 *               added test for zero width or height in IHDR;
 *               added test for insufficient IDAT data (minimum 10 bytes)
 * 19960605 AED: released version 1.96
 *               ---------------------
 * 19960605 AED: added -p flag to dump the palette contents (decimal and hex);
 *               cleaned up internals
 * 19960927 AED: released version 1.97
 *               ---------------------
 * 19961231 JB:  add decoding of the zlib header from the first IDAT chunk (16-
 *               bit header code in first two bytes, see print_zlibheader).
 * 19970102 GRR: more sensible zlib-header output (version "1.97grr"); nuked
 *               some tabs; fixed blank lines between files in verbose output
 * 19970106 AED: initialize the command-line flags; add macros to ensure the
 *               error level doesn't go down; return error level to calling
 *               program; consolidate PNG magic on one place; add "-" as input
 *               file for stdin; check for valid tEXt/zTXt keywords per PNG
 *               Spec 1.0; slight modification to output of tEXt/zTXt keywords/
 *               contents; change 'extract' to output only valid chunks (unless
 *               forced)--this may allow one to fix minor errors in a PNG file
 * 19970107 AED: released version 1.98
 *               ---------------------
 * 19970107 GRR: added USE_ZLIB compile option to print line filters (with -vv)
 * 19970110 GRR: fixed line-filters code for large-IDAT case
 * 19970621 GRR: added compression-ratio info
 * 19980609 TGL: fixed pHYs buglet
 * 19980609 GRR: re-integrated minimal MNG support from 97.01.21 branch
 * 19980610 GRR: extended MNG (MHDR info, DHDR, nEED, DEFI, FRAM, MEND)
 * 19980611 GRR: extended MNG (more FRAM info; LOOP, ENDL)
 * 19980612 GRR: extended MNG (FRAM, BACK, MOVE, CLON, SHOW, CLIP, fPRI, eXPI)
 * 19980616 GRR: extended MNG (PROM, SAVE, SEEK)
 * 19980702 GRR: fixed line-filters bug reported by Theodore Goodman (97.10.19);
 *               updated SAVE for MNG Draft 43
 * 19980711 GRR: added sPLT; extended printpal (-p) to support tRNS, hIST, sPLT
 * 19981021 GRR: added Win32 fix and compilation info; fixed mng=0, DEFI and
 *               printpal bugs
 * 19981206 GRR: added "File: %s" for printpal; fixed some plural%s; fixed and
 *               extended unknown-chunk info (separate line now); added dpi info
 *               to pHYs and flagged unit types > 1 as error
 * 19981228 GRR: nuked old comments; added proto-copyright message
 * 19990201 GRR: changed control-character warning to "one or more"
 * 19990327 GRR: added option to indent printtext; changed non-verbose summary
 *               to two lines; added tRNS info to summary
 * 19990613 GRR: fixed remaining "must precede IDAT" messages for MNG; updated
 *               MHDR and LOOP for Draft 64
 * 19990619 GRR: released version 1.99-grr1
 *               --------------------------
 * 19990620 GRR: fixed Glenn's e-mail address and help-screen MNG-draft version;
 *               disabled compression ratio for MNG; updated FRAM for Draft 64;
 *               fixed "not enough IDAT data" IEND bug; renamed
 *               PNG_MNG_check_magic() to check_magic(); renamed
 *               PNG_check_chunk_name() to check_chunk_name();
 * 19990713 GRP: fixed MNG global-PLTE case (zero-length allowed)
 * 19990718 GRR: shortened non-verbose summary so fits on one line again; added
 *               BASI and PPLT
 * 19991114 GRR: added gIFg, gIFx and part of gIFt
 * 19991117 GRR: finished gIFt; added sRGB and iCCP
 * 19991117 GRR: released version 1.99.2
 *               -----------------------
 * 19991122 GRR: fixed typo in gIFx application ID format (%.*s)
 * 19991215 GRR: added notes about wildcard expansion under Windows
 * 20000304 GRR: fixed indentation on -vt printing of zTXt chunk; fixed bogus
 *               double-backslash bug in printtext(); added -vvvv data-dump
 *               capability (very crude, not correct, ... needs much work)
 * 20000902 GRR: added JNG support; JHDR, JDAT, JSEP; fRAc, iTXt, pCAL, mkBF,
 *               mkBS, mkBT, prVW
 * 20000902 GRR: released version 1.99.3
 *               -----------------------
 * 20000904 GRR: updated usage screen to include JNG; changed dtime to double
 *               to quiet an MSVC conversion warning
 * 20000905 GRR: quieted several IRIX gcc warnings
 * 20000927 GRR: fixed formatting error when both -v and -p options given;
 *               incorporated Tom Zerucha <tz@execpc.com>'s patch to use zlib
 *               CRC routines if USE_ZLIB defined
 * 20001127 GRR: fixed MNG "incorrect [tRNS] length for grayscale image" bug
 * 20010104 GRR: added support for profile bits 6-9, with minimal checking of
 *               10-15 and 16-30
 * 20010116 GRR: incorported Glenn's USE_ZLIB interlacing bugfix of 20000727
 * 20010127 GRR: enhanced summary lines for PNG/MNG/JNG; fixed MNG "sBIT must
 *               precede PLTE" bug
 * 20011209 GRR: started adding PAST support (incomplete!); further work on
 *               summary lines and error-detection?
 * 20020922 GRR: fixed verbose missing newlines for SEEK and empty SAVE chunks
 * 20040120 GRR: fixed missing error level for zlib_error (thanks to Gerrit
 *               Hannaert for the bug report) and for "not enough IDAT data"
 *               (thanks to Eduardo Morras for the test file)
 * 20050712 GRR: updated/fixed SAVE support according to final MNG spec
 * 20050716 GRR: updated/fixed BACK support according to final MNG spec; added
 *               TERM support; added summary of errors if multiple files;
 *               incorporated Paul Matzke's Mac fixes; incorporated Darren
 *               Salt's RISC OS fixes; fixed bad-PNG-signature bug; fixed bKGD
 *               index-out-of-range bug; fixed typos ("pHYS", IDAT vs. JDAT);
 *               cleaned up code and output formatting
 * 20050717 GRR: enabled zlib checking independent of verbosity level; added
 *               more stringent zlib windowBits test (from John Bowler) to
 *               check for libpng 1.2.6 bug; added -w option to disable
 *               windowBits test; fixed faulty zlib "error" detection
 * 20050717 GRR: released version 2.0.0
 *               ----------------------
 * 20050723 GRR: added checks for duplicate SAVE and SEEK without SAVE;
 *               finished PAST and added DISC support
 * 20050724 GRR: updated pHYs with aspect ratio; added pHYg, DROP, DBYK, ORDR,
 *               and MAGN support; added check_keyword() function; fixed zlib-
 *               initialization bug in MNG delta-PNGs
 * 20050725 GRR: added error-checks for unknown public chunks and chunks with
 *               reserved bit set
 * 20050727 GRR: fixed -f bug (failure to read CRC bytes)
 * 20050801 GRR: added png-fix-IDAT-windowsize utility (GNU GPL)
 * 20050814 GRR: added pngsplit utility (GNU GPL) -- still beta!
 * 20060617 GRR: added checks for too-big chunk length, missing PLTE in type-3
 *               (palette) image, missing IDAT in PNG image, missing JDAT in
 *               JNG image, and private/critical chunks (warning only) (thanks
 *               to Chris Nokleberg for "brokensuite" test files); added
 *               CRITICAL, RESERVED, etc., macros; changed slightly confusing
 *               CRC error message ("actual/should be" -> "computed/expected");
 *               added sTER support
 * 20060617 GRR: released version 2.1.0
 *               ----------------------
 * 20061202 GRR: always print a per-file summary (even if error(s))
 * 20061203 GRR: added tests for all but two of the error conditions present
 *               in Chris Nokleberg's brokensuite-20061201; added new warning
 *               level (treat as OK if private test, error if public); started
 *               reducing dependence on global variables; added final totals
 *               for errors, warnings, and "OK" files; switched to logical
 *               names for error levels; fixed some inconsistent error levels;
 *               started removing unsafe ASCII assumptions; added checks for
 *               (private) cmOD, cpIp chunks; filled in old (missing) version
 *               info in CHANGELOG
 * 20061203 GRR: released version 2.2.0
 *               ----------------------
 * 20070211 GRR: extended pngsplit file-signature recognizer to support MNG and
 *               JNG (as claimed in help screen)
 * 20070704 GRR: cleaner fix for narrow interlaced images (account for missing
 *               passes); added rows per pass for interlaced images; added
 *               pass-separators in -vv row-filter output; added -c option for
 *               ANSI colors (filenames, chunk names, row filters, error/OK);
 *               alphabetized options on usage screen; made const string-arrays
 *               const
 * 20070707 GRR: fixed 64-bit ptrdiff_t printf() issue (%td); added check for
 *               NULLs (and "discouraged" chars) in tEXt; added check for zero
 *               values in sCAL; fixed error cascade for private interlace
 *               method; fixed non-verbose-mode IDAT/PLTE message
 * 20070707 GRR: released version 2.3.0
 *               ----------------------
 * 20070709 GRR: tweaked color definitions slightly to work better on terminals
 *               with white/light backgrounds
 * 20070712 GRR: added Makefile.mingw32
 * 20100504 GRR: fixed DHDR (pre-MNG-1.0) bug identified by Winfried <szukw000@arcor.de>
 * 20170713 GRP: added eXIf support (GRR: added check for II/MM/unknown format)
 * 20201012 BB:  converted static const help/usage-related strings to macros so
 *               -Werror=format-security doesn't trigger (Ben Beasley)
 * 20201015 BB:  added (help2man-generated) man pages for all three utils
 * 20201017 GRR: added top-level LICENSE file; fixed various compiler warnings
 * 20201031 GRR: replaced gpl/COPYING (outdated address, references to Library
 *               GPL) with https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
 *               (thanks to Ben Beasley for catching that)
 * 20201031 GRR: released version 2.4.0
 *               ----------------------
 * 20201113 BB:  fixed buffer-overflow vulnerability discovered by "giantbranch
 *               of NSFOCUS Security Team"
 *               https://bugzilla.redhat.com/show_bug.cgi?id=1897485
 * 20201128 BB:  found and fixed four additional vulnerabilities (null-pointer
 *               dereference and three buffer overruns)
 * 20201209 LP:  fixed an off-by-one bug in check_magic() (Lucy Phipps)
 * 20201209 LL:  converted two zlib-version warnings/errors to go to stderr
 *               (Lemures Lemniscati, actually from 20180318; forwarded by LP)
 * 20201210 BB:  fixed another buffer-overflow vulnerability discovered by
 *               "giantbranch of NSFOCUS Security Team"
 *               https://bugzilla.redhat.com/show_bug.cgi?id=1905775
 * 20201212 GRR: removed -f ("force") option due to multiple security issues
 * 20201212 GRR: released version 3.0.0
 *               ----------------------
 * 20201214 BB:  generalized previous sPLT buffer-overrun fix, and found and
 *               fixed a PPLT vulnerability
 * 20210124 GRR: released version 3.0.1
 *               ----------------------
 * 20201217 BB:  fixed a crash bug (and probable vulnerability) in large (MNG)
 *               LOOP chunks
 * 20210131 GRR: updated Makefile.mingw32 for modern versions and added
 *               Makefile.mingw64 (targets Win64); both are essentially
 *               UNTESTED, however!
 * 20210131 GRR: released version 3.0.2
 *               ----------------------
 * 20210416 BB:  fixed a divide-by-zero crash bug (and probable vulnerability)
 *               in interlaced images with extra compressed data beyond the
 *               nominal end of the image data (found by "chiba of topsec alpha
 *               lab")
 * 20210425 GRR: released version 3.0.3
 *               ----------------------
