提交 a4517b4b 编写于 作者: P prr

8208353: Upgrade JDK 8u to libpng 1.6.35

Reviewed-by: serb, jdv
上级 c86faaf6
#if 0
CHANGES - changes for libpng CHANGES - changes for libpng
version 0.1 [March 29, 1995] version 0.1 [March 29, 1995]
...@@ -833,7 +832,7 @@ Version 1.0.7beta11 [May 7, 2000] ...@@ -833,7 +832,7 @@ Version 1.0.7beta11 [May 7, 2000]
Removed the new PNG_CREATED_READ_STRUCT and PNG_CREATED_WRITE_STRUCT modes Removed the new PNG_CREATED_READ_STRUCT and PNG_CREATED_WRITE_STRUCT modes
which are no longer used. which are no longer used.
Eliminated the three new members of png_text when PNG_LEGACY_SUPPORTED is Eliminated the three new members of png_text when PNG_LEGACY_SUPPORTED is
defined or when neither PNG_READ_iTXt_SUPPORTED nor PNG_WRITE_iTXT_SUPPORTED defined or when neither PNG_READ_iTXt_SUPPORTED nor PNG_WRITE_iTXt_SUPPORTED
is defined. is defined.
Made PNG_NO_READ|WRITE_iTXt the default setting, to avoid memory Made PNG_NO_READ|WRITE_iTXt the default setting, to avoid memory
overrun when old applications fill the info_ptr->text structure directly. overrun when old applications fill the info_ptr->text structure directly.
...@@ -1454,7 +1453,7 @@ Version 1.2.6beta4 [July 28, 2004] ...@@ -1454,7 +1453,7 @@ Version 1.2.6beta4 [July 28, 2004]
sequential read support. sequential read support.
Added some "#if PNG_WRITE_SUPPORTED" blocks. Added some "#if PNG_WRITE_SUPPORTED" blocks.
Added #ifdef to remove some redundancy in png_malloc_default(). Added #ifdef to remove some redundancy in png_malloc_default().
Use png_malloc instead of png_zalloc to allocate the pallete. Use png_malloc instead of png_zalloc to allocate the palette.
Version 1.0.16rc1 and 1.2.6rc1 [August 4, 2004] Version 1.0.16rc1 and 1.2.6rc1 [August 4, 2004]
Fixed buffer overflow vulnerability (CVE-2004-0597) in png_handle_tRNS(). Fixed buffer overflow vulnerability (CVE-2004-0597) in png_handle_tRNS().
...@@ -3259,7 +3258,7 @@ Version 1.5.2beta01 [February 13, 2011] ...@@ -3259,7 +3258,7 @@ Version 1.5.2beta01 [February 13, 2011]
Revised PNG_EXPORTA macro to not use an empty parameter, to accommodate the Revised PNG_EXPORTA macro to not use an empty parameter, to accommodate the
old VisualC++ preprocessor. old VisualC++ preprocessor.
Turned on interlace handling in png_read_png(). Turned on interlace handling in png_read_png().
Fixed gcc pendantic warnings. Fixed gcc pedantic warnings.
Handle longjmp in Cygwin. Handle longjmp in Cygwin.
Fixed png_get_current_row_number() in the interlaced case. Fixed png_get_current_row_number() in the interlaced case.
Cleaned up ALPHA flags and transformations. Cleaned up ALPHA flags and transformations.
...@@ -3359,7 +3358,7 @@ Version 1.5.3beta05 [May 6, 2011] ...@@ -3359,7 +3358,7 @@ Version 1.5.3beta05 [May 6, 2011]
Pass "" instead of '\0' to png_default_error() in png_err(). This mistake Pass "" instead of '\0' to png_default_error() in png_err(). This mistake
was introduced in libpng-1.2.20beta01. This fixes CVE-2011-2691. was introduced in libpng-1.2.20beta01. This fixes CVE-2011-2691.
Added PNG_WRITE_OPTIMIZE_CMF_SUPPORTED macro to make the zlib "CMF" byte Added PNG_WRITE_OPTIMIZE_CMF_SUPPORTED macro to make the zlib "CMF" byte
optimization configureable. optimization configurable.
IDAT compression failed if preceded by a compressed text chunk (bug IDAT compression failed if preceded by a compressed text chunk (bug
introduced in libpng-1.5.3beta01-02). This was because the attempt to introduced in libpng-1.5.3beta01-02). This was because the attempt to
reset the zlib stream in png_write_IDAT happened after the first IDAT reset the zlib stream in png_write_IDAT happened after the first IDAT
...@@ -3643,7 +3642,7 @@ Version 1.5.6beta05 [October 12, 2011] ...@@ -3643,7 +3642,7 @@ Version 1.5.6beta05 [October 12, 2011]
Fixed bug in png_write_chunk_header() debug print, introduced in 1.5.6beta01. Fixed bug in png_write_chunk_header() debug print, introduced in 1.5.6beta01.
Version 1.5.6beta06 [October 17, 2011] Version 1.5.6beta06 [October 17, 2011]
Removed two redundant tests for unitialized row. Removed two redundant tests for uninitialized row.
Fixed a relatively harmless memory overwrite in compressed text writing Fixed a relatively harmless memory overwrite in compressed text writing
with a 1 byte zlib buffer. with a 1 byte zlib buffer.
Add ability to call png_read_update_info multiple times to pngvalid.c. Add ability to call png_read_update_info multiple times to pngvalid.c.
...@@ -3689,7 +3688,7 @@ Version 1.5.7beta01 [November 4, 2011] ...@@ -3689,7 +3688,7 @@ Version 1.5.7beta01 [November 4, 2011]
crash. The pngmem.c implementation of png_malloc() included a cast crash. The pngmem.c implementation of png_malloc() included a cast
to png_size_t which would fail on large allocations on 16-bit systems. to png_size_t which would fail on large allocations on 16-bit systems.
Fix for the preprocessor of the Intel C compiler. The preprocessor Fix for the preprocessor of the Intel C compiler. The preprocessor
splits adjacent @ signs with a space; this changes the concatentation splits adjacent @ signs with a space; this changes the concatenation
token from @-@-@ to PNG_JOIN; that should work with all compiler token from @-@-@ to PNG_JOIN; that should work with all compiler
preprocessors. preprocessors.
Paeth filter speed improvements from work by Siarhei Siamashka. This Paeth filter speed improvements from work by Siarhei Siamashka. This
...@@ -3735,7 +3734,7 @@ Version 1.5.7beta03 [November 17, 2011] ...@@ -3735,7 +3734,7 @@ Version 1.5.7beta03 [November 17, 2011]
gray (on palette) itself. gray (on palette) itself.
Fixes for C++ compilation using g++ When libpng source is compiled Fixes for C++ compilation using g++ When libpng source is compiled
using g++. The compiler imposes C++ rules on the C source; thus it using g++. The compiler imposes C++ rules on the C source; thus it
is desireable to make the source work with either C or C++ rules is desirable to make the source work with either C or C++ rules
without throwing away useful error information. This change adds without throwing away useful error information. This change adds
png_voidcast to allow C semantic (void*) cases or the corresponding png_voidcast to allow C semantic (void*) cases or the corresponding
C++ static_cast operation, as appropriate. C++ static_cast operation, as appropriate.
...@@ -4061,7 +4060,7 @@ Version 1.6.0beta17 [March 10, 2012] ...@@ -4061,7 +4060,7 @@ Version 1.6.0beta17 [March 10, 2012]
possible to call png_inflate() incrementally. A warning is no longer possible to call png_inflate() incrementally. A warning is no longer
issued if the language tag or translated keyword in the iTXt chunk issued if the language tag or translated keyword in the iTXt chunk
has zero length. has zero length.
If benign errors are disabled use maximum window on ancilliary inflate. If benign errors are disabled use maximum window on ancillary inflate.
This works round a bug introduced in 1.5.4 where compressed ancillary This works round a bug introduced in 1.5.4 where compressed ancillary
chunks could end up with a too-small windowBits value in the deflate chunks could end up with a too-small windowBits value in the deflate
header. header.
...@@ -4176,7 +4175,7 @@ Version 1.6.0beta27 [August 11, 2012] ...@@ -4176,7 +4175,7 @@ Version 1.6.0beta27 [August 11, 2012]
declared even though the functions are never actually defined. This declared even though the functions are never actually defined. This
change provides a dummy definition so that the declarations work, yet any change provides a dummy definition so that the declarations work, yet any
implementation will fail to compile because of an incomplete type. implementation will fail to compile because of an incomplete type.
Re-eliminated the use of strcpy() in pngtest.c. An unncessary use of Re-eliminated the use of strcpy() in pngtest.c. An unnecessary use of
strcpy() was accidentally re-introduced in libpng16; this change replaces strcpy() was accidentally re-introduced in libpng16; this change replaces
it with strncpy(). it with strncpy().
Eliminated use of png_sizeof(); use sizeof() instead. Eliminated use of png_sizeof(); use sizeof() instead.
...@@ -4309,7 +4308,7 @@ Version 1.6.0beta31 [November 1, 2012] ...@@ -4309,7 +4308,7 @@ Version 1.6.0beta31 [November 1, 2012]
resulting in VS2010 having to update the files. resulting in VS2010 having to update the files.
Removed non-working ICC profile support code that was mostly added to Removed non-working ICC profile support code that was mostly added to
libpng-1.6.0beta29 and beta30. There was too much code for too little libpng-1.6.0beta29 and beta30. There was too much code for too little
gain; implementing full ICC color correction may be desireable but is left gain; implementing full ICC color correction may be desirable but is left
up to applications. up to applications.
Version 1.6.0beta32 [November 25, 2012] Version 1.6.0beta32 [November 25, 2012]
...@@ -4592,7 +4591,7 @@ Version 1.6.3beta07 [June 8, 2013] ...@@ -4592,7 +4591,7 @@ Version 1.6.3beta07 [June 8, 2013]
the optimizations ('check' vs 'api') are exposed in the public header files the optimizations ('check' vs 'api') are exposed in the public header files
except that the new setting PNG_ARM_NEON_OPT documents how libpng makes the except that the new setting PNG_ARM_NEON_OPT documents how libpng makes the
decision about whether or not to use the optimizations. decision about whether or not to use the optimizations.
Protect symbol prefixing against CC/CPPFLAGS/CFLAGS useage. Protect symbol prefixing against CC/CPPFLAGS/CFLAGS usage.
Previous iOS/Xcode fixes for the ARM NEON optimizations moved the test Previous iOS/Xcode fixes for the ARM NEON optimizations moved the test
on __ARM_NEON__ from configure time to compile time. This breaks symbol on __ARM_NEON__ from configure time to compile time. This breaks symbol
prefixing because the definition of the special png_init_filter_functions prefixing because the definition of the special png_init_filter_functions
...@@ -5635,7 +5634,7 @@ Version 1.6.24beta02 [June 23, 2016] ...@@ -5635,7 +5634,7 @@ Version 1.6.24beta02 [June 23, 2016]
to All and adds a list of the warnings that need to be turned off. This is to All and adds a list of the warnings that need to be turned off. This is
semi-documentary; the intent is to tell libpng users which warnings have semi-documentary; the intent is to tell libpng users which warnings have
been examined and judged non-fixable at present. The warning about been examined and judged non-fixable at present. The warning about
structure padding is fixable, but it would be a signficant change (moving structure padding is fixable, but it would be a significant change (moving
structure members around). structure members around).
Version 1.6.24beta03 [July 4, 2016] Version 1.6.24beta03 [July 4, 2016]
...@@ -5761,7 +5760,9 @@ Version 1.6.27beta01 [November 2, 2016] ...@@ -5761,7 +5760,9 @@ Version 1.6.27beta01 [November 2, 2016]
if built with zlib-1.2.8.1. if built with zlib-1.2.8.1.
Version 1.6.27rc01 [December 27, 2016] Version 1.6.27rc01 [December 27, 2016]
Control ADLER32 checking with new PNG_IGNORE_ADLER32 option. Control ADLER32 checking with new PNG_IGNORE_ADLER32 option. Fixes
an endless loop when handling erroneous ADLER32 checksums; bug
introduced in libpng-1.6.26.
Removed the use of a macro containing the pre-processor 'defined' Removed the use of a macro containing the pre-processor 'defined'
operator. It is unclear whether this is valid; a macro that operator. It is unclear whether this is valid; a macro that
"generates" 'defined' is not permitted, but the use of the word "generates" 'defined' is not permitted, but the use of the word
...@@ -5779,7 +5780,7 @@ Version 1.6.28rc01 [January 3, 2017] ...@@ -5779,7 +5780,7 @@ Version 1.6.28rc01 [January 3, 2017]
Added option to Cmake build allowing a custom location of zlib to be Added option to Cmake build allowing a custom location of zlib to be
specified in a scenario where libpng is being built as a subproject specified in a scenario where libpng is being built as a subproject
alongside zlib by another project (Sam Serrels). alongside zlib by another project (Sam Serrels).
Changed png_ptr->options from a png_byte to png_uint_32, to accomodate Changed png_ptr->options from a png_byte to png_uint_32, to accommodate
up to 16 options. up to 16 options.
Version 1.6.28rc02 [January 4, 2017] Version 1.6.28rc02 [January 4, 2017]
...@@ -5794,11 +5795,277 @@ Version 1.6.28rc03 [January 4, 2017] ...@@ -5794,11 +5795,277 @@ Version 1.6.28rc03 [January 4, 2017]
Version 1.6.28 [January 5, 2017] Version 1.6.28 [January 5, 2017]
No changes. No changes.
Version 1.6.29beta01 [January 12, 2017]
Readded "include(GNUInstallDirs)" to CMakeLists.txt (Gianfranco Costamagna).
Moved SSE2 optimization code into the main libpng source directory.
Configure libpng with "configure --enable-intel-sse" or compile
libpng with "-DPNG_INTEL_SSE" in CPPFLAGS to enable it.
Simplified conditional compilation in pngvalid.c, for AIX (Michael Felt).
Version 1.6.29beta02 [February 22, 2017]
Avoid conditional directives that break statements in pngrutil.c (Romero
Malaquias)
The contrib/examples/pngtopng.c recovery code was in the wrong "if"
branches; the comments were correct.
Added code for PowerPC VSX optimisation (Vadim Barkov).
Version 1.6.29beta03 [March 1, 2017]
Avoid potential overflow of shift operations in png_do_expand() (Aaron Boxer).
Change test ZLIB_VERNUM >= 0x1281 to ZLIB_VERNUM >= 0x1290 in pngrutil.c
because Solaris 11 distributes zlib-1.2.8.f that is older than 1.2.8.1,
as suggested in zlib FAQ, item 24.
Suppress clang warnings about implicit sign changes in png.c
Version 1.6.29 [March 16, 2017]
No changes.
Version 1.6.30beta01 [April 1, 2017]
Added missing "$(CPPFLAGS)" to the compile line for c.pic.o in
makefile.linux and makefile.solaris-x86 (Cosmin).
Revised documentation of png_get_error_ptr() in the libpng manual.
Silence clang -Wcomma and const drop warnings (Viktor Szakats).
Update Sourceforge URLs in documentation (https instead of http).
Version 1.6.30beta02 [April 22, 2017]
Document need to check for integer overflow when allocating a pixel
buffer for multiple rows in contrib/gregbook, contrib/pngminus,
example.c, and in the manual (suggested by Jaeseung Choi). This
is similar to the bug reported against pngquant in CVE-2016-5735.
Removed reference to the obsolete PNG_SAFE_LIMITS macro in the documentation.
Version 1.6.30beta03 [May 22, 2017]
Check for integer overflow in contrib/visupng and contrib/tools/genpng.
Do not double evaluate CMAKE_SYSTEM_PROCESSOR in CMakeLists.txt.
Test CMAKE_HOST_WIN32 instead of WIN32 in CMakeLists.txt.
Fix some URL in documentation.
Version 1.6.30beta04 [June 7, 2017]
Avoid writing an empty IDAT when the last IDAT exactly fills the
compression buffer (bug report by Brian Baird). This bug was
introduced in libpng-1.6.0.
Version 1.6.30rc01 [June 14, 2017]
No changes.
Version 1.6.30rc02 [June 25, 2017]
Update copyright year in pnglibconf.h, make ltmain.sh executable.
Add a reference to the libpng.download site in README.
Version 1.6.30 [June 28, 2017]
No changes.
Version 1.6.31beta01 [July 5, 2017]
Guard the definition of _POSIX_SOURCE in pngpriv.h (AIX already defines it;
bug report by Michael Felt).
Revised pngpriv.h to work around failure to compile arm/filter_neon.S
("typedef" directive is unrecognized by the assembler). The problem
was introduced in libpng-1.6.30beta01.
Added "Requires: zlib" to libpng.pc.in (Pieter Neerincx).
Added special case for FreeBSD in arm/filter_neon.S (Maya Rashish).
Version 1.6.31beta02 [July 8, 2017]
Added instructions for disabling hardware optimizations in INSTALL.
Added "--enable-hardware-optimizations" configuration flag to enable
or disable all hardware optimizations with one flag.
Version 1.6.31beta03 [July 9, 2017]
Updated CMakeLists.txt to add INTEL_SSE and MIPS_MSA platforms.
Changed "int" to "png_size_t" in intel/filter_sse2.c to prevent
possible integer overflow (Bug report by John Bowler).
Quieted "declaration after statement" warnings in intel/filter_sse2.c.
Added scripts/makefile-linux-opt, which has hardware optimizations enabled.
Version 1.6.31beta04 [July 11, 2017]
Removed one of the GCC-7.1.0 'strict-overflow' warnings that result when
integers appear on both sides of a compare. Worked around the others by
forcing the strict-overflow setting in the relevant functions to a level
where they are not reported (John Bowler).
Changed "FALL THROUGH" comments to "FALLTHROUGH" because GCC doesn't like
the space.
Worked around some C-style casts from (void*) because g++ 5.4.0 objects
to them.
Increased the buffer size for 'sprint' to pass the gcc 7.1.0 'sprint
overflow' check that is on by default with -Wall -Wextra.
Version 1.6.31beta05 [July 13, 2017]
Added eXIf chunk support.
Version 1.6.31beta06 [July 17, 2017]
Added a minimal eXIf chunk (with Orientation and FocalLengthIn35mmFilm
tags) to pngtest.png.
Version 1.6.31beta07 [July 18, 2017]
Revised the eXIf chunk in pngtest.png to fix "Bad IFD1 Directory" warning.
Version 1.6.31rc01 [July 19, 2017]
No changes.
Version 1.6.31rc02 [July 25, 2017]
Fixed typo in example.c (png_free_image should be png_image_free) (Bug
report by John Smith)
Version 1.6.31 [July 27, 2017]
No changes.
Version 1.6.32beta01 [July 31, 2017]
Avoid possible NULL dereference in png_handle_eXIf when benign_errors
are allowed. Avoid leaking the input buffer "eXIf_buf".
Eliminated png_ptr->num_exif member from pngstruct.h and added num_exif
to arguments for png_get_eXIf() and png_set_eXIf().
Added calls to png_handle_eXIf(() in pngread.c and png_write_eXIf() in
pngwrite.c, and made various other fixes to png_write_eXIf().
Changed name of png_get_eXIF and png_set_eXIf() to png_get_eXIf_1() and
png_set_eXIf_1(), respectively, to avoid breaking API compatibility
with libpng-1.6.31.
Version 1.6.32beta02 [August 1, 2017]
Updated contrib/libtests/pngunknown.c with eXIf chunk.
Version 1.6.32beta03 [August 2, 2017]
Initialized btoa[] in pngstest.c
Stop memory leak when returning from png_handle_eXIf() with an error
(Bug report from the OSS-fuzz project).
Version 1.6.32beta04 [August 2, 2017]
Replaced local eXIf_buf with info_ptr-eXIf_buf in png_handle_eXIf().
Update libpng.3 and libpng-manual.txt about eXIf functions.
Version 1.6.32beta05 [August 2, 2017]
Restored png_get_eXIf() and png_set_eXIf() to maintain API compatibility.
Version 1.6.32beta06 [August 2, 2017]
Removed png_get_eXIf_1() and png_set_eXIf_1().
Version 1.6.32beta07 [August 3, 2017]
Check length of all chunks except IDAT against user limit to fix an
OSS-fuzz issue (Fixes CVE-2017-12652).
Version 1.6.32beta08 [August 3, 2017]
Check length of IDAT against maximum possible IDAT size, accounting
for height, rowbytes, interlacing and zlib/deflate overhead.
Restored png_get_eXIf_1() and png_set_eXIf_1(), because strlen(eXIf_buf)
does not work (the eXIf chunk data can contain zeroes).
Version 1.6.32beta09 [August 3, 2017]
Require cmake-2.8.8 in CMakeLists.txt. Revised symlink creation,
no longer using deprecated cmake LOCATION feature (Clifford Yapp).
Fixed five-byte error in the calculation of IDAT maximum possible size.
Version 1.6.32beta10 [August 5, 2017]
Moved chunk-length check into a png_check_chunk_length() private
function (Suggested by Max Stepin).
Moved bad pngs from tests to contrib/libtests/crashers
Moved testing of bad pngs into a separate tests/pngtest-badpngs script
Added the --xfail (expected FAIL) option to pngtest.c. It writes XFAIL
in the output but PASS for the libpng test.
Require cmake-3.0.2 in CMakeLists.txt (Clifford Yapp).
Fix "const" declaration info_ptr argument to png_get_eXIf_1() and the
num_exif argument to png_get_eXIf_1() (Github Issue 171).
Version 1.6.32beta11 [August 7, 2017]
Added "eXIf" to "chunks_to_ignore[]" in png_set_keep_unknown_chunks().
Added huge_IDAT.png and empty_ancillary_chunks.png to testpngs/crashers.
Make pngtest --strict, --relax, --xfail options imply -m (multiple).
Removed unused chunk_name parameter from png_check_chunk_length().
Relocated setting free_me for eXIf data, to stop an OSS-fuzz leak.
Initialize profile_header[] in png_handle_iCCP() to fix OSS-fuzz issue.
Initialize png_ptr->row_buf[0] to 255 in png_read_row() to fix OSS-fuzz UMR.
Attempt to fix a UMR in png_set_text_2() to fix OSS-fuzz issue.
Increase minimum zlib stream from 9 to 14 in png_handle_iCCP(), to account
for the minimum 'deflate' stream, and relocate the test to a point
after the keyword has been read.
Check that the eXIf chunk has at least 2 bytes and begins with "II" or "MM".
Version 1.6.32rc01 [August 18, 2017]
Added a set of "huge_xxxx_chunk.png" files to contrib/testpngs/crashers,
one for each known chunk type, with length = 2GB-1.
Check for 0 return from png_get_rowbytes() and added some (size_t) typecasts
in contrib/pngminus/*.c to stop some Coverity issues (162705, 162706,
and 162707).
Renamed chunks in contrib/testpngs/crashers to avoid having files whose
names differ only in case; this causes problems with some platforms
(github issue #172).
Version 1.6.32rc02 [August 22, 2017]
Added contrib/oss-fuzz directory which contains files used by the oss-fuzz
project (https://github.com/google/oss-fuzz/tree/master/projects/libpng).
Version 1.6.32 [August 24, 2017]
No changes.
Version 1.6.33beta01 [August 28, 2017]
Added PNGMINUS_UNUSED macro to contrib/pngminus/p*.c and added missing
parenthesis in contrib/pngminus/pnm2png.c (bug report by Christian Hesse).
Fixed off-by-one error in png_do_check_palette_indexes() (Bug report
by Mick P., Source Forge Issue #269).
Version 1.6.33beta02 [September 3, 2017]
Initialize png_handler.row_ptr in contrib/oss-fuzz/libpng_read_fuzzer.cc
to fix shortlived oss-fuzz issue 3234.
Compute a larger limit on IDAT because some applications write a deflate
buffer for each row (Bug report by Andrew Church).
Use current date (DATE) instead of release-date (RDATE) in last
changed date of contrib/oss-fuzz files.
Enabled ARM support in CMakeLists.txt (Bernd Kuhls).
Version 1.6.33beta03 [September 14, 2017]
Fixed incorrect typecast of some arguments to png_malloc() and
png_calloc() that were png_uint_32 instead of png_alloc_size_t
(Bug report by "irwir" in Github libpng issue #175).
Use pnglibconf.h.prebuilt when building for ANDROID with cmake (Github
issue 162, by rcdailey).
Version 1.6.33rc01 [September 20, 2017]
Initialize memory allocated by png_inflate to zero, using memset, to
stop an oss-fuzz "use of uninitialized value" detection in png_set_text_2()
due to truncated iTXt or zTXt chunk.
Initialize memory allocated by png_read_buffer to zero, using memset, to
stop an oss-fuzz "use of uninitialized value" detection in
png_icc_check_tag_table() due to truncated iCCP chunk.
Removed a redundant test (suggested by "irwir" in Github issue #180).
Version 1.6.33rc02 [September 23, 2017]
Added an interlaced version of each file in contrib/pngsuite.
Relocate new memset() call in pngrutil.c.
Removed more redundant tests (suggested by "irwir" in Github issue #180).
Add support for loading images with associated alpha in the Simplified
API (Samuel Williams).
Version 1.6.33 [September 28, 2017]
Revert contrib/oss-fuzz/libpng_read_fuzzer.cc to libpng-1.6.32 state.
Initialize png_handler.row_ptr in contrib/oss-fuzz/libpng_read_fuzzer.cc
Add end_info structure and png_read_end() to the libpng fuzzer.
Version 1.6.34 [September 29, 2017]
Removed contrib/pngsuite/i*.png; some of them caused test failures.
Version 1.6.35beta01 [March 6, 2018]
Restored 21 of the contrib/pngsuite/i*.png, which do not cause test
failures. Placed the remainder in contrib/pngsuite/interlaced/i*.png.
Added calls to png_set_*() transforms commonly used by browsers to
the fuzzer.
Removed some unnecessary brackets in pngrtran.c
Fixed miscellaneous typos (Patch by github user "luzpaz").
Change "ASM C" to "C ASM" in CMakeLists.txt
Fixed incorrect handling of bKGD chunk in sub-8-bit files (Cosmin)
Added hardware optimization directories to zip and 7z distributions.
Fixed incorrect bitmask for options.
Fixed many spelling typos.
Version 1.6.35beta02 [March 28, 2018]
Make png_get_iCCP consistent with man page (allow compression-type argument
to be NULL, bug report by Lenard Szolnoki).
Version 1.6.35 [July 15, 2018]
Replaced the remaining uses of png_size_t with size_t (Cosmin)
Fixed the calculation of row_factor in png_check_chunk_length
(reported by Thuan Pham in SourceForge issue #278)
Added missing parentheses to a macro definition
(suggested by "irwir" in GitHub issue #216)
Send comments/corrections/commendations to png-mng-implement at lists.sf.net Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit (subscription required; visit
https://lists.sourceforge.net/lists/listinfo/png-mng-implement https://lists.sourceforge.net/lists/listinfo/png-mng-implement
to subscribe) to subscribe).
or to glennrp at users.sourceforge.net
Glenn R-P Glenn R-P
#endif
...@@ -10,8 +10,8 @@ this sentence. ...@@ -10,8 +10,8 @@ this sentence.
This code is released under the libpng license. This code is released under the libpng license.
libpng versions 1.0.7, July 1, 2000 through 1.6.28, January 5, 2017 are libpng versions 1.0.7, July 1, 2000 through 1.6.35, July 15, 2018 are
Copyright (c) 2000-2002, 2004, 2006-2017 Glenn Randers-Pehrson, are Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson, are
derived from libpng-1.0.6, and are distributed according to the same derived from libpng-1.0.6, and are distributed according to the same
disclaimer and license as libpng-1.0.6 with the following individuals disclaimer and license as libpng-1.0.6 with the following individuals
added to the list of Contributing Authors: added to the list of Contributing Authors:
...@@ -23,6 +23,8 @@ added to the list of Contributing Authors: ...@@ -23,6 +23,8 @@ added to the list of Contributing Authors:
Gilles Vollant Gilles Vollant
James Yu James Yu
Mandar Sahastrabuddhe Mandar Sahastrabuddhe
Google Inc.
Vadim Barkov
and with the following additions to the disclaimer: and with the following additions to the disclaimer:
...@@ -128,4 +130,4 @@ any encryption software. See the EAR, paragraphs 734.3(b)(3) and ...@@ -128,4 +130,4 @@ any encryption software. See the EAR, paragraphs 734.3(b)(3) and
Glenn Randers-Pehrson Glenn Randers-Pehrson
glennrp at users.sourceforge.net glennrp at users.sourceforge.net
January 5, 2017 July 15, 2018
README for libpng version 1.6.28 - January 5, 2017 (shared library 16.0) README for libpng version 1.6.35 - July 15, 2018 (shared library 16.0)
See the note about version numbers near the top of png.h See the note about version numbers near the top of png.h
See INSTALL for instructions on how to install libpng. See INSTALL for instructions on how to install libpng.
...@@ -23,7 +23,7 @@ earlier versions if you are using a shared library. The type of the ...@@ -23,7 +23,7 @@ earlier versions if you are using a shared library. The type of the
png_uint_32, which will affect shared-library applications that use png_uint_32, which will affect shared-library applications that use
this function. this function.
To avoid problems with changes to the internals of png info_struct, To avoid problems with changes to the internals of the png info_struct,
new APIs have been made available in 0.95 to avoid direct application new APIs have been made available in 0.95 to avoid direct application
access to info_ptr. These functions are the png_set_<chunk> and access to info_ptr. These functions are the png_set_<chunk> and
png_get_<chunk> functions. These functions should be used when png_get_<chunk> functions. These functions should be used when
...@@ -88,11 +88,11 @@ zlib should be available at the same place that libpng is, or at zlib.net. ...@@ -88,11 +88,11 @@ zlib should be available at the same place that libpng is, or at zlib.net.
You may also want a copy of the PNG specification. It is available You may also want a copy of the PNG specification. It is available
as an RFC, a W3C Recommendation, and an ISO/IEC Standard. You can find as an RFC, a W3C Recommendation, and an ISO/IEC Standard. You can find
these at http://www.libpng.org/pub/png/documents/ these at http://www.libpng.org/pub/png/pngdocs.html .
This code is currently being archived at libpng.sf.net in the This code is currently being archived at libpng.sourceforge.io in the
[DOWNLOAD] area, and at ftp://ftp.simplesystems.org. If you can't find it [DOWNLOAD] area, and at http://libpng.download/src . If you
in any of those places, e-mail me, and I'll help you find it. can't find it in any of those places, e-mail me, and I'll help you find it.
I am not a lawyer, but I believe that the Export Control Classification I am not a lawyer, but I believe that the Export Control Classification
Number (ECCN) for libpng is EAR99, which means not subject to export Number (ECCN) for libpng is EAR99, which means not subject to export
...@@ -118,7 +118,7 @@ development group. ...@@ -118,7 +118,7 @@ development group.
Send comments/corrections/commendations to png-mng-implement at Send comments/corrections/commendations to png-mng-implement at
lists.sourceforge.net (subscription required; visit lists.sourceforge.net (subscription required; visit
https://lists.sourceforge.net/lists/listinfo/png-mng-implement https://lists.sourceforge.net/lists/listinfo/png-mng-implement
to subscribe) or to glennrp at users.sourceforge.net to subscribe).
You can't reach Guy, the original libpng author, at the addresses You can't reach Guy, the original libpng author, at the addresses
given in previous versions of this document. He and Andreas will given in previous versions of this document. He and Andreas will
...@@ -179,14 +179,16 @@ Files in this distribution: ...@@ -179,14 +179,16 @@ Files in this distribution:
pngwtran.c => Write data transformations pngwtran.c => Write data transformations
pngwutil.c => Write utility functions pngwutil.c => Write utility functions
arm => Contains optimized code for the ARM platform arm => Contains optimized code for the ARM platform
powerpc => Contains optimized code for the PowerPC platform
contrib => Contributions contrib => Contributions
arm-neon => Optimized code for ARM-NEON platform arm-neon => Optimized code for ARM-NEON platform
powerpc-vsx => Optimized code for POWERPC-VSX platform
examples => Example programs examples => Example programs
gregbook => source code for PNG reading and writing, from gregbook => source code for PNG reading and writing, from
Greg Roelofs' "PNG: The Definitive Guide", Greg Roelofs' "PNG: The Definitive Guide",
O'Reilly, 1999 O'Reilly, 1999
intel => Optimized code for INTEL-SSE2 platform
libtests => Test programs libtests => Test programs
mips-msa => Optimized code for MIPS-MSA platform
pngminim => Minimal decoder, encoder, and progressive decoder pngminim => Minimal decoder, encoder, and progressive decoder
programs demonstrating use of pngusr.dfa programs demonstrating use of pngusr.dfa
pngminus => Simple pnm2png and png2pnm programs pngminus => Simple pnm2png and png2pnm programs
...@@ -194,6 +196,8 @@ Files in this distribution: ...@@ -194,6 +196,8 @@ Files in this distribution:
testpngs testpngs
tools => Various tools tools => Various tools
visupng => Contains a MSVC workspace for VisualPng visupng => Contains a MSVC workspace for VisualPng
intel => Optimized code for INTEL-SSE2 platform
mips => Optimized code for MIPS platform
projects => Contains project files and workspaces for projects => Contains project files and workspaces for
building a DLL building a DLL
owatcom => Contains a WATCOM project for building libpng owatcom => Contains a WATCOM project for building libpng
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
* However, the following notice accompanied the original version of this * However, the following notice accompanied the original version of this
* file and, per its terms, should not be removed: * file and, per its terms, should not be removed:
* *
* Last changed in libpng 1.6.28 [January 5, 2017] * Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
...@@ -42,7 +42,27 @@ ...@@ -42,7 +42,27 @@
#include "pngpriv.h" #include "pngpriv.h"
/* Generate a compiler error if there is an old png.h in the search path. */ /* Generate a compiler error if there is an old png.h in the search path. */
typedef png_libpng_version_1_6_28 Your_png_h_is_not_version_1_6_28; typedef png_libpng_version_1_6_35 Your_png_h_is_not_version_1_6_35;
#ifdef __GNUC__
/* The version tests may need to be added to, but the problem warning has
* consistently been fixed in GCC versions which obtain wide-spread release.
* The problem is that many versions of GCC rearrange comparison expressions in
* the optimizer in such a way that the results of the comparison will change
* if signed integer overflow occurs. Such comparisons are not permitted in
* ANSI C90, however GCC isn't clever enough to work out that that do not occur
* below in png_ascii_from_fp and png_muldiv, so it produces a warning with
* -Wextra. Unfortunately this is highly dependent on the optimizer and the
* machine architecture so the warning comes and goes unpredictably and is
* impossible to "fix", even were that a good idea.
*/
#if __GNUC__ == 7 && __GNUC_MINOR__ == 1
#define GCC_STRICT_OVERFLOW 1
#endif /* GNU 7.1.x */
#endif /* GNU */
#ifndef GCC_STRICT_OVERFLOW
#define GCC_STRICT_OVERFLOW 0
#endif
/* Tells libpng that we have already handled the first "num_bytes" bytes /* 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 * of the PNG file signature. If the PNG data is embedded into another
...@@ -79,7 +99,7 @@ png_set_sig_bytes(png_structrp png_ptr, int num_bytes) ...@@ -79,7 +99,7 @@ png_set_sig_bytes(png_structrp png_ptr, int num_bytes)
* PNG signature (this is the same behavior as strcmp, memcmp, etc). * PNG signature (this is the same behavior as strcmp, memcmp, etc).
*/ */
int PNGAPI int PNGAPI
png_sig_cmp(png_const_bytep sig, png_size_t start, png_size_t num_to_check) png_sig_cmp(png_const_bytep sig, size_t start, size_t num_to_check)
{ {
png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
...@@ -144,7 +164,7 @@ png_reset_crc(png_structrp png_ptr) ...@@ -144,7 +164,7 @@ png_reset_crc(png_structrp png_ptr)
* trouble of calculating it. * trouble of calculating it.
*/ */
void /* PRIVATE */ void /* PRIVATE */
png_calculate_crc(png_structrp png_ptr, png_const_bytep ptr, png_size_t length) png_calculate_crc(png_structrp png_ptr, png_const_bytep ptr, size_t length)
{ {
int need_crc = 1; int need_crc = 1;
...@@ -429,7 +449,7 @@ png_destroy_info_struct(png_const_structrp png_ptr, png_infopp info_ptr_ptr) ...@@ -429,7 +449,7 @@ png_destroy_info_struct(png_const_structrp png_ptr, png_infopp info_ptr_ptr)
* those cases where it does anything other than a memset. * those cases where it does anything other than a memset.
*/ */
PNG_FUNCTION(void,PNGAPI PNG_FUNCTION(void,PNGAPI
png_info_init_3,(png_infopp ptr_ptr, png_size_t png_info_struct_size), png_info_init_3,(png_infopp ptr_ptr, size_t png_info_struct_size),
PNG_DEPRECATED) PNG_DEPRECATED)
{ {
png_inforp info_ptr = *ptr_ptr; png_inforp info_ptr = *ptr_ptr;
...@@ -623,6 +643,26 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask, ...@@ -623,6 +643,26 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
} }
#endif #endif
#ifdef PNG_eXIf_SUPPORTED
/* Free any eXIf entry */
if (((mask & PNG_FREE_EXIF) & info_ptr->free_me) != 0)
{
# ifdef PNG_READ_eXIf_SUPPORTED
if (info_ptr->eXIf_buf)
{
png_free(png_ptr, info_ptr->eXIf_buf);
info_ptr->eXIf_buf = NULL;
}
# endif
if (info_ptr->exif)
{
png_free(png_ptr, info_ptr->exif);
info_ptr->exif = NULL;
}
info_ptr->valid &= ~PNG_INFO_eXIf;
}
#endif
#ifdef PNG_hIST_SUPPORTED #ifdef PNG_hIST_SUPPORTED
/* Free any hIST entry */ /* Free any hIST entry */
if (((mask & PNG_FREE_HIST) & info_ptr->free_me) != 0) if (((mask & PNG_FREE_HIST) & info_ptr->free_me) != 0)
...@@ -804,15 +844,15 @@ png_get_copyright(png_const_structrp png_ptr) ...@@ -804,15 +844,15 @@ png_get_copyright(png_const_structrp png_ptr)
#else #else
# ifdef __STDC__ # ifdef __STDC__
return PNG_STRING_NEWLINE \ return PNG_STRING_NEWLINE \
"libpng version 1.6.28 - January 5, 2017" PNG_STRING_NEWLINE \ "libpng version 1.6.35 - July 15, 2018" PNG_STRING_NEWLINE \
"Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson" \ "Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson" \
PNG_STRING_NEWLINE \ PNG_STRING_NEWLINE \
"Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
"Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
PNG_STRING_NEWLINE; PNG_STRING_NEWLINE;
# else # else
return "libpng version 1.6.28 - January 5, 2017\ return "libpng version 1.6.35 - July 15, 2018\
Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson\ Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson\
Copyright (c) 1996-1997 Andreas Dilger\ Copyright (c) 1996-1997 Andreas Dilger\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."; Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
# endif # endif
...@@ -930,7 +970,7 @@ png_handle_as_unknown(png_const_structrp png_ptr, png_const_bytep chunk_name) ...@@ -930,7 +970,7 @@ png_handle_as_unknown(png_const_structrp png_ptr, png_const_bytep chunk_name)
/* The code is the fifth byte after each four byte string. Historically this /* The code is the fifth byte after each four byte string. Historically this
* code was always searched from the end of the list, this is no longer * code was always searched from the end of the list, this is no longer
* necessary because the 'set' routine handles duplicate entries correcty. * necessary because the 'set' routine handles duplicate entries correctly.
*/ */
do /* num_chunk_list > 0, so at least one */ do /* num_chunk_list > 0, so at least one */
{ {
...@@ -1901,12 +1941,12 @@ png_colorspace_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace, ...@@ -1901,12 +1941,12 @@ png_colorspace_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace,
*/ */
if (intent < 0 || intent >= PNG_sRGB_INTENT_LAST) if (intent < 0 || intent >= PNG_sRGB_INTENT_LAST)
return png_icc_profile_error(png_ptr, colorspace, "sRGB", return png_icc_profile_error(png_ptr, colorspace, "sRGB",
(unsigned)intent, "invalid sRGB rendering intent"); (png_alloc_size_t)intent, "invalid sRGB rendering intent");
if ((colorspace->flags & PNG_COLORSPACE_HAVE_INTENT) != 0 && if ((colorspace->flags & PNG_COLORSPACE_HAVE_INTENT) != 0 &&
colorspace->rendering_intent != intent) colorspace->rendering_intent != intent)
return png_icc_profile_error(png_ptr, colorspace, "sRGB", return png_icc_profile_error(png_ptr, colorspace, "sRGB",
(unsigned)intent, "inconsistent rendering intents"); (png_alloc_size_t)intent, "inconsistent rendering intents");
if ((colorspace->flags & PNG_COLORSPACE_FROM_sRGB) != 0) if ((colorspace->flags & PNG_COLORSPACE_FROM_sRGB) != 0)
{ {
...@@ -1967,7 +2007,6 @@ icc_check_length(png_const_structrp png_ptr, png_colorspacerp colorspace, ...@@ -1967,7 +2007,6 @@ icc_check_length(png_const_structrp png_ptr, png_colorspacerp colorspace,
if (profile_length < 132) if (profile_length < 132)
return png_icc_profile_error(png_ptr, colorspace, name, profile_length, return png_icc_profile_error(png_ptr, colorspace, name, profile_length,
"too short"); "too short");
return 1; return 1;
} }
...@@ -2056,7 +2095,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace, ...@@ -2056,7 +2095,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
*/ */
/* Data checks (could be skipped). These checks must be independent of the /* Data checks (could be skipped). These checks must be independent of the
* version number; however, the version number doesn't accomodate changes in * version number; however, the version number doesn't accommodate changes in
* the header fields (just the known tags and the interpretation of the * the header fields (just the known tags and the interpretation of the
* data.) * data.)
*/ */
...@@ -2212,22 +2251,23 @@ png_icc_check_tag_table(png_const_structrp png_ptr, png_colorspacerp colorspace, ...@@ -2212,22 +2251,23 @@ png_icc_check_tag_table(png_const_structrp png_ptr, png_colorspacerp colorspace,
* being in range. All defined tag types have an 8 byte header - a 4 byte * being in range. All defined tag types have an 8 byte header - a 4 byte
* type signature then 0. * type signature then 0.
*/ */
/* This is a hard error; potentially it can cause read outside the
* profile.
*/
if (tag_start > profile_length || tag_length > profile_length - tag_start)
return png_icc_profile_error(png_ptr, colorspace, name, tag_id,
"ICC profile tag outside profile");
if ((tag_start & 3) != 0) if ((tag_start & 3) != 0)
{ {
/* CNHP730S.icc shipped with Microsoft Windows 64 violates this, it is /* CNHP730S.icc shipped with Microsoft Windows 64 violates this; it is
* only a warning here because libpng does not care about the * only a warning here because libpng does not care about the
* alignment. * alignment.
*/ */
(void)png_icc_profile_error(png_ptr, NULL, name, tag_id, (void)png_icc_profile_error(png_ptr, NULL, name, tag_id,
"ICC profile tag start not a multiple of 4"); "ICC profile tag start not a multiple of 4");
} }
/* This is a hard error; potentially it can cause read outside the
* profile.
*/
if (tag_start > profile_length || tag_length > profile_length - tag_start)
return png_icc_profile_error(png_ptr, colorspace, name, tag_id,
"ICC profile tag outside profile");
} }
return 1; /* success, maybe with warnings */ return 1; /* success, maybe with warnings */
...@@ -2695,7 +2735,7 @@ png_check_IHDR(png_const_structrp png_ptr, ...@@ -2695,7 +2735,7 @@ png_check_IHDR(png_const_structrp png_ptr,
#if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED) #if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED)
/* ASCII to fp functions */ /* ASCII to fp functions */
/* Check an ASCII formated floating point value, see the more detailed /* Check an ASCII formatted floating point value, see the more detailed
* comments in pngpriv.h * comments in pngpriv.h
*/ */
/* The following is used internally to preserve the sticky flags */ /* The following is used internally to preserve the sticky flags */
...@@ -2703,11 +2743,11 @@ png_check_IHDR(png_const_structrp png_ptr, ...@@ -2703,11 +2743,11 @@ png_check_IHDR(png_const_structrp png_ptr,
#define png_fp_set(state, value) ((state) = (value) | ((state) & PNG_FP_STICKY)) #define png_fp_set(state, value) ((state) = (value) | ((state) & PNG_FP_STICKY))
int /* PRIVATE */ int /* PRIVATE */
png_check_fp_number(png_const_charp string, png_size_t size, int *statep, png_check_fp_number(png_const_charp string, size_t size, int *statep,
png_size_tp whereami) png_size_tp whereami)
{ {
int state = *statep; int state = *statep;
png_size_t i = *whereami; size_t i = *whereami;
while (i < size) while (i < size)
{ {
...@@ -2830,10 +2870,10 @@ PNG_FP_End: ...@@ -2830,10 +2870,10 @@ PNG_FP_End:
/* The same but for a complete string. */ /* The same but for a complete string. */
int int
png_check_fp_string(png_const_charp string, png_size_t size) png_check_fp_string(png_const_charp string, size_t size)
{ {
int state=0; int state=0;
png_size_t char_index=0; size_t char_index=0;
if (png_check_fp_number(string, size, &state, &char_index) != 0 && if (png_check_fp_number(string, size, &state, &char_index) != 0 &&
(char_index == size || string[char_index] == 0)) (char_index == size || string[char_index] == 0))
...@@ -2860,7 +2900,7 @@ png_pow10(int power) ...@@ -2860,7 +2900,7 @@ png_pow10(int power)
if (power < 0) if (power < 0)
{ {
if (power < DBL_MIN_10_EXP) return 0; if (power < DBL_MIN_10_EXP) return 0;
recip = 1, power = -power; recip = 1; power = -power;
} }
if (power > 0) if (power > 0)
...@@ -2885,8 +2925,16 @@ png_pow10(int power) ...@@ -2885,8 +2925,16 @@ png_pow10(int power)
/* Function to format a floating point value in ASCII with a given /* Function to format a floating point value in ASCII with a given
* precision. * precision.
*/ */
#if GCC_STRICT_OVERFLOW
#pragma GCC diagnostic push
/* The problem arises below with exp_b10, which can never overflow because it
* comes, originally, from frexp and is therefore limited to a range which is
* typically +/-710 (log2(DBL_MAX)/log2(DBL_MIN)).
*/
#pragma GCC diagnostic warning "-Wstrict-overflow=2"
#endif /* GCC_STRICT_OVERFLOW */
void /* PRIVATE */ void /* PRIVATE */
png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, size_t size,
double fp, unsigned int precision) double fp, unsigned int precision)
{ {
/* We use standard functions from math.h, but not printf because /* We use standard functions from math.h, but not printf because
...@@ -2938,7 +2986,9 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, ...@@ -2938,7 +2986,9 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
double test = png_pow10(exp_b10+1); double test = png_pow10(exp_b10+1);
if (test <= DBL_MAX) if (test <= DBL_MAX)
++exp_b10, base = test; {
++exp_b10; base = test;
}
else else
break; break;
...@@ -2952,7 +3002,10 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, ...@@ -2952,7 +3002,10 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
* test on DBL_MAX above. * test on DBL_MAX above.
*/ */
fp /= base; fp /= base;
while (fp >= 1) fp /= 10, ++exp_b10; while (fp >= 1)
{
fp /= 10; ++exp_b10;
}
/* Because of the code above fp may, at this point, be /* Because of the code above fp may, at this point, be
* less than .1, this is ok because the code below can * less than .1, this is ok because the code below can
...@@ -2969,7 +3022,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, ...@@ -2969,7 +3022,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
*/ */
if (exp_b10 < 0 && exp_b10 > -3) /* PLUS 3 TOTAL 4 */ if (exp_b10 < 0 && exp_b10 > -3) /* PLUS 3 TOTAL 4 */
{ {
czero = (unsigned int)(-exp_b10); /* PLUS 2 digits: TOTAL 3 */ czero = 0U-exp_b10; /* PLUS 2 digits: TOTAL 3 */
exp_b10 = 0; /* Dot added below before first output. */ exp_b10 = 0; /* Dot added below before first output. */
} }
else else
...@@ -3003,7 +3056,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, ...@@ -3003,7 +3056,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
/* Rounding up to 10, handle that here. */ /* Rounding up to 10, handle that here. */
if (czero > 0) if (czero > 0)
{ {
--czero, d = 1; --czero; d = 1;
if (cdigits == 0) --clead; if (cdigits == 0) --clead;
} }
else else
...@@ -3017,7 +3070,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, ...@@ -3017,7 +3070,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
else if (ch == 46) else if (ch == 46)
{ {
ch = *--ascii, ++size; ch = *--ascii; ++size;
/* Advance exp_b10 to '1', so that the /* Advance exp_b10 to '1', so that the
* decimal point happens after the * decimal point happens after the
* previous digit. * previous digit.
...@@ -3044,7 +3097,9 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, ...@@ -3044,7 +3097,9 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
int ch = *--ascii; int ch = *--ascii;
if (ch == 46) if (ch == 46)
++size, exp_b10 = 1; {
++size; exp_b10 = 1;
}
/* Else lost a leading zero, so 'exp_b10' is /* Else lost a leading zero, so 'exp_b10' is
* still ok at (-1) * still ok at (-1)
...@@ -3080,21 +3135,26 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, ...@@ -3080,21 +3135,26 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
*/ */
if (exp_b10 != (-1)) if (exp_b10 != (-1))
{ {
if (exp_b10 == 0) *ascii++ = 46, --size; if (exp_b10 == 0)
{
*ascii++ = 46; --size;
}
/* PLUS 1: TOTAL 4 */ /* PLUS 1: TOTAL 4 */
--exp_b10; --exp_b10;
} }
*ascii++ = 48, --czero; *ascii++ = 48; --czero;
} }
if (exp_b10 != (-1)) if (exp_b10 != (-1))
{ {
if (exp_b10 == 0) if (exp_b10 == 0)
*ascii++ = 46, --size; /* counted above */ {
*ascii++ = 46; --size; /* counted above */
}
--exp_b10; --exp_b10;
} }
*ascii++ = (char)(48 + (int)d), ++cdigits; *ascii++ = (char)(48 + (int)d); ++cdigits;
} }
} }
while (cdigits+czero < precision+clead && fp > DBL_MIN); while (cdigits+czero < precision+clead && fp > DBL_MIN);
...@@ -3103,7 +3163,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, ...@@ -3103,7 +3163,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
/* Check for an exponent, if we don't need one we are /* Check for an exponent, if we don't need one we are
* done and just need to terminate the string. At * done and just need to terminate the string. At
* this point exp_b10==(-1) is effectively if flag - it got * this point exp_b10==(-1) is effectively a flag - it got
* to '-1' because of the decrement after outputting * to '-1' because of the decrement after outputting
* the decimal point above (the exponent required is * the decimal point above (the exponent required is
* *not* -1!) * *not* -1!)
...@@ -3117,7 +3177,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, ...@@ -3117,7 +3177,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
* zeros were *not* output, so this doesn't increase * zeros were *not* output, so this doesn't increase
* the output count. * the output count.
*/ */
while (--exp_b10 >= 0) *ascii++ = 48; while (exp_b10-- > 0) *ascii++ = 48;
*ascii = 0; *ascii = 0;
...@@ -3135,7 +3195,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, ...@@ -3135,7 +3195,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
*/ */
size -= cdigits; size -= cdigits;
*ascii++ = 69, --size; /* 'E': PLUS 1 TOTAL 2+precision */ *ascii++ = 69; --size; /* 'E': PLUS 1 TOTAL 2+precision */
/* The following use of an unsigned temporary avoids ambiguities in /* The following use of an unsigned temporary avoids ambiguities in
* the signed arithmetic on exp_b10 and permits GCC at least to do * the signed arithmetic on exp_b10 and permits GCC at least to do
...@@ -3146,12 +3206,12 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, ...@@ -3146,12 +3206,12 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
if (exp_b10 < 0) if (exp_b10 < 0)
{ {
*ascii++ = 45, --size; /* '-': PLUS 1 TOTAL 3+precision */ *ascii++ = 45; --size; /* '-': PLUS 1 TOTAL 3+precision */
uexp_b10 = (unsigned int)(-exp_b10); uexp_b10 = 0U-exp_b10;
} }
else else
uexp_b10 = (unsigned int)exp_b10; uexp_b10 = 0U+exp_b10;
cdigits = 0; cdigits = 0;
...@@ -3194,6 +3254,9 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, ...@@ -3194,6 +3254,9 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
/* Here on buffer too small. */ /* Here on buffer too small. */
png_error(png_ptr, "ASCII conversion buffer too small"); png_error(png_ptr, "ASCII conversion buffer too small");
} }
#if GCC_STRICT_OVERFLOW
#pragma GCC diagnostic pop
#endif /* GCC_STRICT_OVERFLOW */
# endif /* FLOATING_POINT */ # endif /* FLOATING_POINT */
...@@ -3202,7 +3265,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, ...@@ -3202,7 +3265,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
*/ */
void /* PRIVATE */ void /* PRIVATE */
png_ascii_from_fixed(png_const_structrp png_ptr, png_charp ascii, png_ascii_from_fixed(png_const_structrp png_ptr, png_charp ascii,
png_size_t size, png_fixed_point fp) size_t size, png_fixed_point fp)
{ {
/* Require space for 10 decimal digits, a decimal point, a minus sign and a /* Require space for 10 decimal digits, a decimal point, a minus sign and a
* trailing \0, 13 characters: * trailing \0, 13 characters:
...@@ -3213,7 +3276,9 @@ png_ascii_from_fixed(png_const_structrp png_ptr, png_charp ascii, ...@@ -3213,7 +3276,9 @@ png_ascii_from_fixed(png_const_structrp png_ptr, png_charp ascii,
/* Avoid overflow here on the minimum integer. */ /* Avoid overflow here on the minimum integer. */
if (fp < 0) if (fp < 0)
*ascii++ = 45, num = (png_uint_32)(-fp); {
*ascii++ = 45; num = (png_uint_32)(-fp);
}
else else
num = (png_uint_32)fp; num = (png_uint_32)fp;
...@@ -3251,7 +3316,10 @@ png_ascii_from_fixed(png_const_structrp png_ptr, png_charp ascii, ...@@ -3251,7 +3316,10 @@ png_ascii_from_fixed(png_const_structrp png_ptr, png_charp ascii,
* then ndigits digits to first: * then ndigits digits to first:
*/ */
i = 5; i = 5;
while (ndigits < i) *ascii++ = 48, --i; while (ndigits < i)
{
*ascii++ = 48; --i;
}
while (ndigits >= first) *ascii++ = digits[--ndigits]; while (ndigits >= first) *ascii++ = digits[--ndigits];
/* Don't output the trailing zeros! */ /* Don't output the trailing zeros! */
} }
...@@ -3302,6 +3370,15 @@ png_fixed(png_const_structrp png_ptr, double fp, png_const_charp text) ...@@ -3302,6 +3370,15 @@ png_fixed(png_const_structrp png_ptr, double fp, png_const_charp text)
* the nearest .00001). Overflow and divide by zero are signalled in * the nearest .00001). Overflow and divide by zero are signalled in
* the result, a boolean - true on success, false on overflow. * the result, a boolean - true on success, false on overflow.
*/ */
#if GCC_STRICT_OVERFLOW /* from above */
/* It is not obvious which comparison below gets optimized in such a way that
* signed overflow would change the result; looking through the code does not
* reveal any tests which have the form GCC complains about, so presumably the
* optimizer is moving an add or subtract into the 'if' somewhere.
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wstrict-overflow=2"
#endif /* GCC_STRICT_OVERFLOW */
int int
png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times, png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times,
png_int_32 divisor) png_int_32 divisor)
...@@ -3416,6 +3493,9 @@ png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times, ...@@ -3416,6 +3493,9 @@ png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times,
return 0; return 0;
} }
#if GCC_STRICT_OVERFLOW
#pragma GCC diagnostic pop
#endif /* GCC_STRICT_OVERFLOW */
#endif /* READ_GAMMA || INCH_CONVERSIONS */ #endif /* READ_GAMMA || INCH_CONVERSIONS */
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED) #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED)
...@@ -3709,7 +3789,7 @@ png_log16bit(png_uint_32 x) ...@@ -3709,7 +3789,7 @@ png_log16bit(png_uint_32 x)
* of getting this accuracy in practice. * of getting this accuracy in practice.
* *
* To deal with this the following exp() function works out the exponent of the * To deal with this the following exp() function works out the exponent of the
* frational part of the logarithm by using an accurate 32-bit value from the * fractional part of the logarithm by using an accurate 32-bit value from the
* top four fractional bits then multiplying in the remaining bits. * top four fractional bits then multiplying in the remaining bits.
*/ */
static const png_uint_32 static const png_uint_32
...@@ -4288,13 +4368,13 @@ png_set_option(png_structrp png_ptr, int option, int onoff) ...@@ -4288,13 +4368,13 @@ png_set_option(png_structrp png_ptr, int option, int onoff)
if (png_ptr != NULL && option >= 0 && option < PNG_OPTION_NEXT && if (png_ptr != NULL && option >= 0 && option < PNG_OPTION_NEXT &&
(option & 1) == 0) (option & 1) == 0)
{ {
png_uint_32 mask = 3 << option; png_uint_32 mask = 3U << option;
png_uint_32 setting = (2 + (onoff != 0)) << option; png_uint_32 setting = (2U + (onoff != 0)) << option;
png_uint_32 current = png_ptr->options; png_uint_32 current = png_ptr->options;
png_ptr->options = (png_uint_32)(((current & ~mask) | setting) & 0xff); png_ptr->options = (png_uint_32)((current & ~mask) | setting);
return (current & mask) >> option; return (int)(current & mask) >> option;
} }
return PNG_OPTION_INVALID; return PNG_OPTION_INVALID;
...@@ -4306,7 +4386,7 @@ png_set_option(png_structrp png_ptr, int option, int onoff) ...@@ -4306,7 +4386,7 @@ png_set_option(png_structrp png_ptr, int option, int onoff)
defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
/* sRGB conversion tables; these are machine generated with the code in /* sRGB conversion tables; these are machine generated with the code in
* contrib/tools/makesRGB.c. The actual sRGB transfer curve defined in the * contrib/tools/makesRGB.c. The actual sRGB transfer curve defined in the
* specification (see the article at http://en.wikipedia.org/wiki/SRGB) * specification (see the article at https://en.wikipedia.org/wiki/SRGB)
* is used, not the gamma=1/2.2 approximation use elsewhere in libpng. * is used, not the gamma=1/2.2 approximation use elsewhere in libpng.
* The sRGB to linear table is exact (to the nearest 16-bit linear fraction). * The sRGB to linear table is exact (to the nearest 16-bit linear fraction).
* The inverse (linear to sRGB) table has accuracies as follows: * The inverse (linear to sRGB) table has accuracies as follows:
......
...@@ -29,9 +29,9 @@ ...@@ -29,9 +29,9 @@
* However, the following notice accompanied the original version of this * However, the following notice accompanied the original version of this
* file and, per its terms, should not be removed: * file and, per its terms, should not be removed:
* *
* libpng version 1.6.28, January 5, 2017 * libpng version 1.6.35, July 15, 2018
* *
* Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
* Authors and maintainers: * Authors and maintainers:
* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
* libpng versions 0.89, June 1996, through 0.96, May 1997: Andreas Dilger * libpng versions 0.89, June 1996, through 0.96, May 1997: Andreas Dilger
* libpng versions 0.97, January 1998, through 1.6.28, January 5, 2017: * libpng versions 0.97, January 1998, through 1.6.35, July 15, 2018:
* Glenn Randers-Pehrson. * Glenn Randers-Pehrson.
* See also "Contributing Authors", below. * See also "Contributing Authors", below.
*/ */
...@@ -53,8 +53,8 @@ ...@@ -53,8 +53,8 @@
* *
* This code is released under the libpng license. * This code is released under the libpng license.
* *
* libpng versions 1.0.7, July 1, 2000 through 1.6.28, January 5, 2017 are * libpng versions 1.0.7, July 1, 2000 through 1.6.35, July 15, 2018 are
* Copyright (c) 2000-2002, 2004, 2006-2017 Glenn Randers-Pehrson, are * Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson, are
* derived from libpng-1.0.6, and are distributed according to the same * derived from libpng-1.0.6, and are distributed according to the same
* disclaimer and license as libpng-1.0.6 with the following individuals * disclaimer and license as libpng-1.0.6 with the following individuals
* added to the list of Contributing Authors: * added to the list of Contributing Authors:
...@@ -66,6 +66,8 @@ ...@@ -66,6 +66,8 @@
* Gilles Vollant * Gilles Vollant
* James Yu * James Yu
* Mandar Sahastrabuddhe * Mandar Sahastrabuddhe
* Google Inc.
* Vadim Barkov
* *
* and with the following additions to the disclaimer: * and with the following additions to the disclaimer:
* *
...@@ -90,9 +92,6 @@ ...@@ -90,9 +92,6 @@
* Glenn Randers-Pehrson * Glenn Randers-Pehrson
* Willem van Schaik * Willem van Schaik
* *
* Some files in the "scripts" directory have different copyright owners
* but are also released under this license.
*
* libpng versions 0.89, June 1996, through 0.96, May 1997, are * libpng versions 0.89, June 1996, through 0.96, May 1997, are
* Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88, * Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88,
* and are distributed according to the same disclaimer and license as * and are distributed according to the same disclaimer and license as
...@@ -238,11 +237,11 @@ ...@@ -238,11 +237,11 @@
* ... * ...
* 1.0.19 10 10019 10.so.0.19[.0] * 1.0.19 10 10019 10.so.0.19[.0]
* ... * ...
* 1.2.57 13 10257 12.so.0.57[.0] * 1.2.59 13 10257 12.so.0.59[.0]
* ... * ...
* 1.5.28 15 10527 15.so.15.28[.0] * 1.5.30 15 10527 15.so.15.30[.0]
* ... * ...
* 1.6.28 16 10628 16.so.16.28[.0] * 1.6.35 16 10635 16.so.16.35[.0]
* *
* Henceforth the source version will match the shared-library major * Henceforth the source version will match the shared-library major
* and minor numbers; the shared-library major version number will be * and minor numbers; the shared-library major version number will be
...@@ -263,20 +262,20 @@ ...@@ -263,20 +262,20 @@
* *
* See libpng.txt or libpng.3 for more information. The PNG specification * See libpng.txt or libpng.3 for more information. The PNG specification
* is available as a W3C Recommendation and as an ISO Specification, * is available as a W3C Recommendation and as an ISO Specification,
* <http://www.w3.org/TR/2003/REC-PNG-20031110/ * <https://www.w3.org/TR/2003/REC-PNG-20031110/
*/ */
/* /*
* Y2K compliance in libpng: * Y2K compliance in libpng:
* ========================= * =========================
* *
* January 5, 2017 * July 15, 2018
* *
* Since the PNG Development group is an ad-hoc body, we can't make * Since the PNG Development group is an ad-hoc body, we can't make
* an official declaration. * an official declaration.
* *
* This is your unofficial assurance that libpng from version 0.71 and * This is your unofficial assurance that libpng from version 0.71 and
* upward through 1.6.28 are Y2K compliant. It is my belief that * upward through 1.6.35 are Y2K compliant. It is my belief that
* earlier versions were also Y2K compliant. * earlier versions were also Y2K compliant.
* *
* Libpng only has two year fields. One is a 2-byte unsigned integer * Libpng only has two year fields. One is a 2-byte unsigned integer
...@@ -338,8 +337,8 @@ ...@@ -338,8 +337,8 @@
*/ */
/* Version information for png.h - this should match the version in png.c */ /* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.6.28" #define PNG_LIBPNG_VER_STRING "1.6.35"
#define PNG_HEADER_VERSION_STRING " libpng version 1.6.28 - January 5, 2017\n" #define PNG_HEADER_VERSION_STRING " libpng version 1.6.35 - July 15, 2018\n"
#define PNG_LIBPNG_VER_SONUM 16 #define PNG_LIBPNG_VER_SONUM 16
#define PNG_LIBPNG_VER_DLLNUM 16 #define PNG_LIBPNG_VER_DLLNUM 16
...@@ -347,13 +346,13 @@ ...@@ -347,13 +346,13 @@
/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */ /* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
#define PNG_LIBPNG_VER_MAJOR 1 #define PNG_LIBPNG_VER_MAJOR 1
#define PNG_LIBPNG_VER_MINOR 6 #define PNG_LIBPNG_VER_MINOR 6
#define PNG_LIBPNG_VER_RELEASE 28 #define PNG_LIBPNG_VER_RELEASE 35
/* This should match the numeric part of the final component of /* This should match the numeric part of the final component of
* PNG_LIBPNG_VER_STRING, omitting any leading zero: * PNG_LIBPNG_VER_STRING, omitting any leading zero:
*/ */
#define PNG_LIBPNG_VER_BUILD 0 #define PNG_LIBPNG_VER_BUILD 02
/* Release Status */ /* Release Status */
#define PNG_LIBPNG_BUILD_ALPHA 1 #define PNG_LIBPNG_BUILD_ALPHA 1
...@@ -370,7 +369,7 @@ ...@@ -370,7 +369,7 @@
#define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
PNG_LIBPNG_BUILD_PRIVATE */ PNG_LIBPNG_BUILD_PRIVATE */
#define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_BETA
/* Careful here. At one time, Guy wanted to use 082, but that would be octal. /* Careful here. At one time, Guy wanted to use 082, but that would be octal.
* We must not include leading zeros. * We must not include leading zeros.
...@@ -378,7 +377,7 @@ ...@@ -378,7 +377,7 @@
* version 1.0.0 was mis-numbered 100 instead of 10000). From * 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 * version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release
*/ */
#define PNG_LIBPNG_VER 10628 /* 1.6.28 */ #define PNG_LIBPNG_VER 10635 /* 1.6.35 */
/* Library configuration: these options cannot be changed after /* Library configuration: these options cannot be changed after
* the library has been built. * the library has been built.
...@@ -488,7 +487,7 @@ extern "C" { ...@@ -488,7 +487,7 @@ extern "C" {
/* This triggers a compiler error in png.c, if png.c and png.h /* This triggers a compiler error in png.c, if png.c and png.h
* do not agree upon the version number. * do not agree upon the version number.
*/ */
typedef char* png_libpng_version_1_6_28; typedef char* png_libpng_version_1_6_35;
/* Basic control structions. Read libpng-manual.txt or libpng.3 for more info. /* Basic control structions. Read libpng-manual.txt or libpng.3 for more info.
* *
...@@ -629,8 +628,8 @@ typedef struct png_text_struct ...@@ -629,8 +628,8 @@ typedef struct png_text_struct
png_charp key; /* keyword, 1-79 character description of "text" */ png_charp key; /* keyword, 1-79 character description of "text" */
png_charp text; /* comment, may be an empty string (ie "") png_charp text; /* comment, may be an empty string (ie "")
or a NULL pointer */ or a NULL pointer */
png_size_t text_length; /* length of the text string */ size_t text_length; /* length of the text string */
png_size_t itxt_length; /* length of the itxt string */ size_t itxt_length; /* length of the itxt string */
png_charp lang; /* language code, 0-79 characters png_charp lang; /* language code, 0-79 characters
or a NULL pointer */ or a NULL pointer */
png_charp lang_key; /* keyword translated UTF-8 string, 0 or more png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
...@@ -683,7 +682,7 @@ typedef struct png_unknown_chunk_t ...@@ -683,7 +682,7 @@ typedef struct png_unknown_chunk_t
{ {
png_byte name[5]; /* Textual chunk name with '\0' terminator */ png_byte name[5]; /* Textual chunk name with '\0' terminator */
png_byte *data; /* Data, should not be modified on read! */ png_byte *data; /* Data, should not be modified on read! */
png_size_t size; size_t size;
/* On write 'location' must be set using the flag values listed below. /* On write 'location' must be set using the flag values listed below.
* Notice that on read it is set by libpng however the values stored have * Notice that on read it is set by libpng however the values stored have
...@@ -708,7 +707,7 @@ typedef png_unknown_chunk * * png_unknown_chunkpp; ...@@ -708,7 +707,7 @@ typedef png_unknown_chunk * * png_unknown_chunkpp;
/* Maximum positive integer used in PNG is (2^31)-1 */ /* Maximum positive integer used in PNG is (2^31)-1 */
#define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL) #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
#define PNG_UINT_32_MAX ((png_uint_32)(-1)) #define PNG_UINT_32_MAX ((png_uint_32)(-1))
#define PNG_SIZE_MAX ((png_size_t)(-1)) #define PNG_SIZE_MAX ((size_t)(-1))
/* These are constants for fixed point values encoded in the /* These are constants for fixed point values encoded in the
* PNG specification manner (x100000) * PNG specification manner (x100000)
...@@ -805,6 +804,7 @@ typedef png_unknown_chunk * * png_unknown_chunkpp; ...@@ -805,6 +804,7 @@ typedef png_unknown_chunk * * png_unknown_chunkpp;
#define PNG_INFO_sPLT 0x2000U /* ESR, 1.0.6 */ #define PNG_INFO_sPLT 0x2000U /* ESR, 1.0.6 */
#define PNG_INFO_sCAL 0x4000U /* ESR, 1.0.6 */ #define PNG_INFO_sCAL 0x4000U /* ESR, 1.0.6 */
#define PNG_INFO_IDAT 0x8000U /* ESR, 1.0.6 */ #define PNG_INFO_IDAT 0x8000U /* ESR, 1.0.6 */
#define PNG_INFO_eXIf 0x10000U /* GR-P, 1.6.31 */
/* This is used for the transformation routines, as some of them /* This is used for the transformation routines, as some of them
* change these values for the row. It also should enable using * change these values for the row. It also should enable using
...@@ -813,7 +813,7 @@ typedef png_unknown_chunk * * png_unknown_chunkpp; ...@@ -813,7 +813,7 @@ typedef png_unknown_chunk * * png_unknown_chunkpp;
typedef struct png_row_info_struct typedef struct png_row_info_struct
{ {
png_uint_32 width; /* width of row */ png_uint_32 width; /* width of row */
png_size_t rowbytes; /* number of bytes in row */ size_t rowbytes; /* number of bytes in row */
png_byte color_type; /* color type of row */ png_byte color_type; /* color type of row */
png_byte bit_depth; /* bit depth of row */ png_byte bit_depth; /* bit depth of row */
png_byte channels; /* number of channels (1, 2, 3, or 4) */ png_byte channels; /* number of channels (1, 2, 3, or 4) */
...@@ -832,7 +832,7 @@ typedef png_row_info * * png_row_infopp; ...@@ -832,7 +832,7 @@ typedef png_row_info * * png_row_infopp;
* expected to return the read data in the buffer. * expected to return the read data in the buffer.
*/ */
typedef PNG_CALLBACK(void, *png_error_ptr, (png_structp, png_const_charp)); typedef PNG_CALLBACK(void, *png_error_ptr, (png_structp, png_const_charp));
typedef PNG_CALLBACK(void, *png_rw_ptr, (png_structp, png_bytep, png_size_t)); typedef PNG_CALLBACK(void, *png_rw_ptr, (png_structp, png_bytep, size_t));
typedef PNG_CALLBACK(void, *png_flush_ptr, (png_structp)); typedef PNG_CALLBACK(void, *png_flush_ptr, (png_structp));
typedef PNG_CALLBACK(void, *png_read_status_ptr, (png_structp, png_uint_32, typedef PNG_CALLBACK(void, *png_read_status_ptr, (png_structp, png_uint_32,
int)); int));
...@@ -969,8 +969,8 @@ PNG_EXPORT(2, void, png_set_sig_bytes, (png_structrp png_ptr, int num_bytes)); ...@@ -969,8 +969,8 @@ PNG_EXPORT(2, void, png_set_sig_bytes, (png_structrp png_ptr, int num_bytes));
* signature, and non-zero otherwise. Having num_to_check == 0 or * signature, and non-zero otherwise. Having num_to_check == 0 or
* start > 7 will always fail (ie return non-zero). * start > 7 will always fail (ie return non-zero).
*/ */
PNG_EXPORT(3, int, png_sig_cmp, (png_const_bytep sig, png_size_t start, PNG_EXPORT(3, int, png_sig_cmp, (png_const_bytep sig, size_t start,
png_size_t num_to_check)); size_t num_to_check));
/* Simple signature checking function. This is the same as calling /* Simple signature checking function. This is the same as calling
* png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n). * png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n).
...@@ -989,11 +989,11 @@ PNG_EXPORTA(5, png_structp, png_create_write_struct, ...@@ -989,11 +989,11 @@ PNG_EXPORTA(5, png_structp, png_create_write_struct,
png_error_ptr warn_fn), png_error_ptr warn_fn),
PNG_ALLOCATED); PNG_ALLOCATED);
PNG_EXPORT(6, png_size_t, png_get_compression_buffer_size, PNG_EXPORT(6, size_t, png_get_compression_buffer_size,
(png_const_structrp png_ptr)); (png_const_structrp png_ptr));
PNG_EXPORT(7, void, png_set_compression_buffer_size, (png_structrp png_ptr, PNG_EXPORT(7, void, png_set_compression_buffer_size, (png_structrp png_ptr,
png_size_t size)); size_t size));
/* Moved from pngconf.h in 1.4.0 and modified to ensure setjmp/longjmp /* Moved from pngconf.h in 1.4.0 and modified to ensure setjmp/longjmp
* match up. * match up.
...@@ -1046,7 +1046,7 @@ PNG_EXPORT(13, void, png_write_sig, (png_structrp png_ptr)); ...@@ -1046,7 +1046,7 @@ PNG_EXPORT(13, void, png_write_sig, (png_structrp png_ptr));
/* Write a PNG chunk - size, type, (optional) data, CRC. */ /* Write a PNG chunk - size, type, (optional) data, CRC. */
PNG_EXPORT(14, void, png_write_chunk, (png_structrp png_ptr, png_const_bytep PNG_EXPORT(14, void, png_write_chunk, (png_structrp png_ptr, png_const_bytep
chunk_name, png_const_bytep data, png_size_t length)); chunk_name, png_const_bytep data, size_t length));
/* Write the start of a PNG chunk - length and chunk name. */ /* Write the start of a PNG chunk - length and chunk name. */
PNG_EXPORT(15, void, png_write_chunk_start, (png_structrp png_ptr, PNG_EXPORT(15, void, png_write_chunk_start, (png_structrp png_ptr,
...@@ -1054,7 +1054,7 @@ PNG_EXPORT(15, void, png_write_chunk_start, (png_structrp png_ptr, ...@@ -1054,7 +1054,7 @@ PNG_EXPORT(15, void, png_write_chunk_start, (png_structrp png_ptr,
/* Write the data of a PNG chunk started with png_write_chunk_start(). */ /* Write the data of a PNG chunk started with png_write_chunk_start(). */
PNG_EXPORT(16, void, png_write_chunk_data, (png_structrp png_ptr, PNG_EXPORT(16, void, png_write_chunk_data, (png_structrp png_ptr,
png_const_bytep data, png_size_t length)); png_const_bytep data, size_t length));
/* Finish a chunk started with png_write_chunk_start() (includes CRC). */ /* Finish a chunk started with png_write_chunk_start() (includes CRC). */
PNG_EXPORT(17, void, png_write_chunk_end, (png_structrp png_ptr)); PNG_EXPORT(17, void, png_write_chunk_end, (png_structrp png_ptr));
...@@ -1068,7 +1068,7 @@ PNG_EXPORTA(18, png_infop, png_create_info_struct, (png_const_structrp png_ptr), ...@@ -1068,7 +1068,7 @@ PNG_EXPORTA(18, png_infop, png_create_info_struct, (png_const_structrp png_ptr),
* the API will be removed in the future. * the API will be removed in the future.
*/ */
PNG_EXPORTA(19, void, png_info_init_3, (png_infopp info_ptr, PNG_EXPORTA(19, void, png_info_init_3, (png_infopp info_ptr,
png_size_t png_info_struct_size), PNG_DEPRECATED); size_t png_info_struct_size), PNG_DEPRECATED);
/* Writes all the PNG information before the image. */ /* Writes all the PNG information before the image. */
PNG_EXPORT(20, void, png_write_info_before_PLTE, PNG_EXPORT(20, void, png_write_info_before_PLTE,
...@@ -1165,7 +1165,7 @@ PNG_EXPORT(35, void, png_build_grayscale_palette, (int bit_depth, ...@@ -1165,7 +1165,7 @@ PNG_EXPORT(35, void, png_build_grayscale_palette, (int bit_depth,
* corresponding composited pixel, and the color channels are unassociated * corresponding composited pixel, and the color channels are unassociated
* (not premultiplied). The gamma encoded color channels must be scaled * (not premultiplied). The gamma encoded color channels must be scaled
* according to the contribution and to do this it is necessary to undo * according to the contribution and to do this it is necessary to undo
* the encoding, scale the color values, perform the composition and reencode * the encoding, scale the color values, perform the composition and re-encode
* the values. This is the 'PNG' mode. * the values. This is the 'PNG' mode.
* *
* The alternative is to 'associate' the alpha with the color information by * The alternative is to 'associate' the alpha with the color information by
...@@ -1221,7 +1221,7 @@ PNG_FIXED_EXPORT(228, void, png_set_alpha_mode_fixed, (png_structrp png_ptr, ...@@ -1221,7 +1221,7 @@ PNG_FIXED_EXPORT(228, void, png_set_alpha_mode_fixed, (png_structrp png_ptr,
* *
* png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC); * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC);
* In this case the output is assumed to be something like an sRGB conformant * In this case the output is assumed to be something like an sRGB conformant
* display preceeded by a power-law lookup table of power 1.45. This is how * display preceded by a power-law lookup table of power 1.45. This is how
* early Mac systems behaved. * early Mac systems behaved.
* *
* png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_GAMMA_LINEAR); * png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_GAMMA_LINEAR);
...@@ -1268,7 +1268,7 @@ PNG_FIXED_EXPORT(228, void, png_set_alpha_mode_fixed, (png_structrp png_ptr, ...@@ -1268,7 +1268,7 @@ PNG_FIXED_EXPORT(228, void, png_set_alpha_mode_fixed, (png_structrp png_ptr,
* *
* When the default gamma of PNG files doesn't match the output gamma. * When the default gamma of PNG files doesn't match the output gamma.
* If you have PNG files with no gamma information png_set_alpha_mode allows * If you have PNG files with no gamma information png_set_alpha_mode allows
* you to provide a default gamma, but it also sets the ouput gamma to the * you to provide a default gamma, but it also sets the output gamma to the
* matching value. If you know your PNG files have a gamma that doesn't * matching value. If you know your PNG files have a gamma that doesn't
* match the output you can take advantage of the fact that * match the output you can take advantage of the fact that
* png_set_alpha_mode always sets the output gamma but only sets the PNG * png_set_alpha_mode always sets the output gamma but only sets the PNG
...@@ -1719,7 +1719,7 @@ PNG_EXPORT(218, png_byte, png_get_current_pass_number, (png_const_structrp)); ...@@ -1719,7 +1719,7 @@ PNG_EXPORT(218, png_byte, png_get_current_pass_number, (png_const_structrp));
* chunk will cause an error at this point unless it is to be saved. * chunk will cause an error at this point unless it is to be saved.
* positive: The chunk was handled, libpng will ignore/discard it. * positive: The chunk was handled, libpng will ignore/discard it.
* *
* See "INTERACTION WTIH USER CHUNK CALLBACKS" below for important notes about * See "INTERACTION WITH USER CHUNK CALLBACKS" below for important notes about
* how this behavior will change in libpng 1.7 * how this behavior will change in libpng 1.7
*/ */
PNG_EXPORT(88, void, png_set_read_user_chunk_fn, (png_structrp png_ptr, PNG_EXPORT(88, void, png_set_read_user_chunk_fn, (png_structrp png_ptr,
...@@ -1744,7 +1744,7 @@ PNG_EXPORT(91, png_voidp, png_get_progressive_ptr, ...@@ -1744,7 +1744,7 @@ PNG_EXPORT(91, png_voidp, png_get_progressive_ptr,
/* Function to be called when data becomes available */ /* Function to be called when data becomes available */
PNG_EXPORT(92, void, png_process_data, (png_structrp png_ptr, PNG_EXPORT(92, void, png_process_data, (png_structrp png_ptr,
png_inforp info_ptr, png_bytep buffer, png_size_t buffer_size)); png_inforp info_ptr, png_bytep buffer, size_t buffer_size));
/* A function which may be called *only* within png_process_data to stop the /* A function which may be called *only* within png_process_data to stop the
* processing of any more data. The function returns the number of bytes * processing of any more data. The function returns the number of bytes
...@@ -1753,7 +1753,7 @@ PNG_EXPORT(92, void, png_process_data, (png_structrp png_ptr, ...@@ -1753,7 +1753,7 @@ PNG_EXPORT(92, void, png_process_data, (png_structrp png_ptr,
* 'save' is set to true the routine will first save all the pending data and * 'save' is set to true the routine will first save all the pending data and
* will always return 0. * will always return 0.
*/ */
PNG_EXPORT(219, png_size_t, png_process_data_pause, (png_structrp, int save)); PNG_EXPORT(219, size_t, png_process_data_pause, (png_structrp, int save));
/* A function which may be called *only* outside (after) a call to /* A function which may be called *only* outside (after) a call to
* png_process_data. It returns the number of bytes of data to skip in the * png_process_data. It returns the number of bytes of data to skip in the
...@@ -1817,7 +1817,8 @@ PNG_EXPORT(99, void, png_data_freer, (png_const_structrp png_ptr, ...@@ -1817,7 +1817,8 @@ PNG_EXPORT(99, void, png_data_freer, (png_const_structrp png_ptr,
#define PNG_FREE_PLTE 0x1000U #define PNG_FREE_PLTE 0x1000U
#define PNG_FREE_TRNS 0x2000U #define PNG_FREE_TRNS 0x2000U
#define PNG_FREE_TEXT 0x4000U #define PNG_FREE_TEXT 0x4000U
#define PNG_FREE_ALL 0x7fffU #define PNG_FREE_EXIF 0x8000U /* Added at libpng-1.6.31 */
#define PNG_FREE_ALL 0xffffU
#define PNG_FREE_MUL 0x4220U /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */ #define PNG_FREE_MUL 0x4220U /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
...@@ -1897,7 +1898,7 @@ PNG_EXPORT(110, png_uint_32, png_get_valid, (png_const_structrp png_ptr, ...@@ -1897,7 +1898,7 @@ PNG_EXPORT(110, png_uint_32, png_get_valid, (png_const_structrp png_ptr,
png_const_inforp info_ptr, png_uint_32 flag)); png_const_inforp info_ptr, png_uint_32 flag));
/* Returns number of bytes needed to hold a transformed row. */ /* Returns number of bytes needed to hold a transformed row. */
PNG_EXPORT(111, png_size_t, png_get_rowbytes, (png_const_structrp png_ptr, PNG_EXPORT(111, size_t, png_get_rowbytes, (png_const_structrp png_ptr,
png_const_inforp info_ptr)); png_const_inforp info_ptr));
#ifdef PNG_INFO_IMAGE_SUPPORTED #ifdef PNG_INFO_IMAGE_SUPPORTED
...@@ -2036,6 +2037,18 @@ PNG_FIXED_EXPORT(233, void, png_set_cHRM_XYZ_fixed, (png_const_structrp png_ptr, ...@@ -2036,6 +2037,18 @@ PNG_FIXED_EXPORT(233, void, png_set_cHRM_XYZ_fixed, (png_const_structrp png_ptr,
png_fixed_point int_blue_Z)) png_fixed_point int_blue_Z))
#endif #endif
#ifdef PNG_eXIf_SUPPORTED
PNG_EXPORT(246, png_uint_32, png_get_eXIf, (png_const_structrp png_ptr,
png_inforp info_ptr, png_bytep *exif));
PNG_EXPORT(247, void, png_set_eXIf, (png_const_structrp png_ptr,
png_inforp info_ptr, const png_bytep exif));
PNG_EXPORT(248, png_uint_32, png_get_eXIf_1, (png_const_structrp png_ptr,
png_const_inforp info_ptr, png_uint_32 *num_exif, png_bytep *exif));
PNG_EXPORT(249, void, png_set_eXIf_1, (png_const_structrp png_ptr,
png_inforp info_ptr, const png_uint_32 num_exif, const png_bytep exif));
#endif
#ifdef PNG_gAMA_SUPPORTED #ifdef PNG_gAMA_SUPPORTED
PNG_FP_EXPORT(137, png_uint_32, png_get_gAMA, (png_const_structrp png_ptr, PNG_FP_EXPORT(137, png_uint_32, png_get_gAMA, (png_const_structrp png_ptr,
png_const_inforp info_ptr, double *file_gamma)) png_const_inforp info_ptr, double *file_gamma))
...@@ -2054,9 +2067,6 @@ PNG_FIXED_EXPORT(140, void, png_set_gAMA_fixed, (png_const_structrp png_ptr, ...@@ -2054,9 +2067,6 @@ PNG_FIXED_EXPORT(140, void, png_set_gAMA_fixed, (png_const_structrp png_ptr,
#ifdef PNG_hIST_SUPPORTED #ifdef PNG_hIST_SUPPORTED
PNG_EXPORT(141, png_uint_32, png_get_hIST, (png_const_structrp png_ptr, PNG_EXPORT(141, png_uint_32, png_get_hIST, (png_const_structrp png_ptr,
png_inforp info_ptr, png_uint_16p *hist)); png_inforp info_ptr, png_uint_16p *hist));
#endif
#ifdef PNG_hIST_SUPPORTED
PNG_EXPORT(142, void, png_set_hIST, (png_const_structrp png_ptr, PNG_EXPORT(142, void, png_set_hIST, (png_const_structrp png_ptr,
png_inforp info_ptr, png_const_uint_16p hist)); png_inforp info_ptr, png_const_uint_16p hist));
#endif #endif
...@@ -2257,7 +2267,7 @@ PNG_EXPORT(171, void, png_set_sCAL_s, (png_const_structrp png_ptr, ...@@ -2257,7 +2267,7 @@ PNG_EXPORT(171, void, png_set_sCAL_s, (png_const_structrp png_ptr,
* to specifying "NEVER", however when "AS_DEFAULT" is used for specific chunks * to specifying "NEVER", however when "AS_DEFAULT" is used for specific chunks
* it simply resets the behavior to the libpng default. * it simply resets the behavior to the libpng default.
* *
* INTERACTION WTIH USER CHUNK CALLBACKS: * INTERACTION WITH USER CHUNK CALLBACKS:
* The per-chunk handling is always used when there is a png_user_chunk_ptr * The per-chunk handling is always used when there is a png_user_chunk_ptr
* callback and the callback returns 0; the chunk is then always stored *unless* * callback and the callback returns 0; the chunk is then always stored *unless*
* it is critical and the per-chunk setting is other than ALWAYS. Notice that * it is critical and the per-chunk setting is other than ALWAYS. Notice that
...@@ -2676,7 +2686,7 @@ PNG_EXPORT(243, int, png_get_palette_max, (png_const_structp png_ptr, ...@@ -2676,7 +2686,7 @@ PNG_EXPORT(243, int, png_get_palette_max, (png_const_structp png_ptr,
* The simplified API hides the details of both libpng and the PNG file format * The simplified API hides the details of both libpng and the PNG file format
* itself. It allows PNG files to be read into a very limited number of * itself. It allows PNG files to be read into a very limited number of
* in-memory bitmap formats or to be written from the same formats. If these * in-memory bitmap formats or to be written from the same formats. If these
* formats do not accomodate your needs then you can, and should, use the more * formats do not accommodate your needs then you can, and should, use the more
* sophisticated APIs above - these support a wide variety of in-memory formats * sophisticated APIs above - these support a wide variety of in-memory formats
* and a wide variety of sophisticated transformations to those formats as well * and a wide variety of sophisticated transformations to those formats as well
* as a wide variety of APIs to manipulate ancillary information. * as a wide variety of APIs to manipulate ancillary information.
...@@ -2782,7 +2792,7 @@ typedef struct ...@@ -2782,7 +2792,7 @@ typedef struct
* *
* When the simplified API needs to convert between sRGB and linear colorspaces, * When the simplified API needs to convert between sRGB and linear colorspaces,
* the actual sRGB transfer curve defined in the sRGB specification (see the * the actual sRGB transfer curve defined in the sRGB specification (see the
* article at http://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2 * article at https://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2
* approximation used elsewhere in libpng. * approximation used elsewhere in libpng.
* *
* When an alpha channel is present it is expected to denote pixel coverage * When an alpha channel is present it is expected to denote pixel coverage
...@@ -2837,6 +2847,8 @@ typedef struct ...@@ -2837,6 +2847,8 @@ typedef struct
# define PNG_FORMAT_FLAG_AFIRST 0x20U /* alpha channel comes first */ # define PNG_FORMAT_FLAG_AFIRST 0x20U /* alpha channel comes first */
#endif #endif
#define PNG_FORMAT_FLAG_ASSOCIATED_ALPHA 0x40U /* alpha channel is associated */
/* Commonly used formats have predefined macros. /* Commonly used formats have predefined macros.
* *
* First the single byte (sRGB) formats: * First the single byte (sRGB) formats:
...@@ -3036,7 +3048,7 @@ PNG_EXPORT(235, int, png_image_begin_read_from_stdio, (png_imagep image, ...@@ -3036,7 +3048,7 @@ PNG_EXPORT(235, int, png_image_begin_read_from_stdio, (png_imagep image,
#endif /* STDIO */ #endif /* STDIO */
PNG_EXPORT(236, int, png_image_begin_read_from_memory, (png_imagep image, PNG_EXPORT(236, int, png_image_begin_read_from_memory, (png_imagep image,
png_const_voidp memory, png_size_t size)); png_const_voidp memory, size_t size));
/* The PNG header is read from the given memory buffer. */ /* The PNG header is read from the given memory buffer. */
PNG_EXPORT(237, int, png_image_finish_read, (png_imagep image, PNG_EXPORT(237, int, png_image_finish_read, (png_imagep image,
...@@ -3149,7 +3161,7 @@ PNG_EXPORT(245, int, png_image_write_to_memory, (png_imagep image, void *memory, ...@@ -3149,7 +3161,7 @@ PNG_EXPORT(245, int, png_image_write_to_memory, (png_imagep image, void *memory,
* than or equal to the original value. * than or equal to the original value.
* *
* If the function returns false and *memory_bytes was not changed an error * If the function returns false and *memory_bytes was not changed an error
* occured during write. If *memory_bytes was changed, or is not 0 if * occurred during write. If *memory_bytes was changed, or is not 0 if
* 'memory' was NULL, the write would have succeeded but for the memory * 'memory' was NULL, the write would have succeeded but for the memory
* buffer being too small. *memory_bytes contains the required number of * buffer being too small. *memory_bytes contains the required number of
* bytes and will be bigger that the original value. * bytes and will be bigger that the original value.
...@@ -3233,7 +3245,7 @@ PNG_EXPORT(245, int, png_image_write_to_memory, (png_imagep image, void *memory, ...@@ -3233,7 +3245,7 @@ PNG_EXPORT(245, int, png_image_write_to_memory, (png_imagep image, void *memory,
* option and 'onoff' is 0 (off) or non-0 (on). The value returned is given * option and 'onoff' is 0 (off) or non-0 (on). The value returned is given
* by the PNG_OPTION_ defines below. * by the PNG_OPTION_ defines below.
* *
* HARDWARE: normally hardware capabilites, such as the Intel SSE instructions, * HARDWARE: normally hardware capabilities, such as the Intel SSE instructions,
* are detected at run time, however sometimes it may be impossible * are detected at run time, however sometimes it may be impossible
* to do this in user mode, in which case it is necessary to discover * to do this in user mode, in which case it is necessary to discover
* the capabilities in an OS specific way. Such capabilities are * the capabilities in an OS specific way. Such capabilities are
...@@ -3255,7 +3267,10 @@ PNG_EXPORT(245, int, png_image_write_to_memory, (png_imagep image, void *memory, ...@@ -3255,7 +3267,10 @@ PNG_EXPORT(245, int, png_image_write_to_memory, (png_imagep image, void *memory,
# define PNG_MIPS_MSA 6 /* HARDWARE: MIPS Msa SIMD instructions supported */ # define PNG_MIPS_MSA 6 /* HARDWARE: MIPS Msa SIMD instructions supported */
#endif #endif
#define PNG_IGNORE_ADLER32 8 #define PNG_IGNORE_ADLER32 8
#define PNG_OPTION_NEXT 10 /* Next option - numbers must be even */ #ifdef PNG_POWERPC_VSX_API_SUPPORTED
# define PNG_POWERPC_VSX 10 /* HARDWARE: PowerPC VSX SIMD instructions supported */
#endif
#define PNG_OPTION_NEXT 12 /* Next option - numbers must be even */
/* Return values: NOTE: there are four values and 'off' is *not* zero */ /* Return values: NOTE: there are four values and 'off' is *not* zero */
#define PNG_OPTION_UNSET 0 /* Unset - defaults to off */ #define PNG_OPTION_UNSET 0 /* Unset - defaults to off */
...@@ -3279,7 +3294,7 @@ PNG_EXPORT(244, int, png_set_option, (png_structrp png_ptr, int option, ...@@ -3279,7 +3294,7 @@ PNG_EXPORT(244, int, png_set_option, (png_structrp png_ptr, int option,
* one to use is one more than this.) * one to use is one more than this.)
*/ */
#ifdef PNG_EXPORT_LAST_ORDINAL #ifdef PNG_EXPORT_LAST_ORDINAL
PNG_EXPORT_LAST_ORDINAL(245); PNG_EXPORT_LAST_ORDINAL(249);
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -29,9 +29,9 @@ ...@@ -29,9 +29,9 @@
* However, the following notice accompanied the original version of this * However, the following notice accompanied the original version of this
* file and, per its terms, should not be removed: * file and, per its terms, should not be removed:
* *
* libpng version 1.6.28, January 5, 2017 * libpng version 1.6.35, July 15, 2018
* *
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2016,2018 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
...@@ -155,7 +155,7 @@ ...@@ -155,7 +155,7 @@
* *
* These cases only differ if the operating system does not use the C * These cases only differ if the operating system does not use the C
* calling convention, at present this just means the above cases * calling convention, at present this just means the above cases
* (x86 DOS/Windows sytems) and, even then, this does not apply to * (x86 DOS/Windows systems) and, even then, this does not apply to
* Cygwin running on those systems. * Cygwin running on those systems.
* *
* Note that the value must be defined in pnglibconf.h so that what * Note that the value must be defined in pnglibconf.h so that what
...@@ -543,8 +543,10 @@ ...@@ -543,8 +543,10 @@
# error "libpng requires an unsigned 32-bit (or more) type" # error "libpng requires an unsigned 32-bit (or more) type"
#endif #endif
/* Prior to 1.6.0 it was possible to disable the use of size_t, 1.6.0, however, /* Prior to 1.6.0, it was possible to disable the use of size_t and ptrdiff_t.
* requires an ISOC90 compiler and relies on consistent behavior of sizeof. * From 1.6.0 onwards, an ISO C90 compiler, as well as a standard-compliant
* behavior of sizeof and ptrdiff_t are required.
* The legacy typedefs are provided here for backwards compatibility.
*/ */
typedef size_t png_size_t; typedef size_t png_size_t;
typedef ptrdiff_t png_ptrdiff_t; typedef ptrdiff_t png_ptrdiff_t;
...@@ -565,13 +567,12 @@ typedef ptrdiff_t png_ptrdiff_t; ...@@ -565,13 +567,12 @@ typedef ptrdiff_t png_ptrdiff_t;
# endif # endif
#endif #endif
/* png_alloc_size_t is guaranteed to be no smaller than png_size_t, and no /* png_alloc_size_t is guaranteed to be no smaller than size_t, and no smaller
* smaller than png_uint_32. Casts from png_size_t or png_uint_32 to * than png_uint_32. Casts from size_t or png_uint_32 to png_alloc_size_t are
* png_alloc_size_t are not necessary; in fact, it is recommended not to use * not necessary; in fact, it is recommended not to use them at all, so that
* them at all so that the compiler can complain when something turns out to be * the compiler can complain when something turns out to be problematic.
* problematic.
* *
* Casts in the other direction (from png_alloc_size_t to png_size_t or * Casts in the other direction (from png_alloc_size_t to size_t or
* png_uint_32) should be explicitly applied; however, we do not expect to * png_uint_32) should be explicitly applied; however, we do not expect to
* encounter practical situations that require such conversions. * encounter practical situations that require such conversions.
* *
...@@ -581,7 +582,7 @@ typedef ptrdiff_t png_ptrdiff_t; ...@@ -581,7 +582,7 @@ typedef ptrdiff_t png_ptrdiff_t;
#ifdef PNG_SMALL_SIZE_T #ifdef PNG_SMALL_SIZE_T
typedef png_uint_32 png_alloc_size_t; typedef png_uint_32 png_alloc_size_t;
#else #else
typedef png_size_t png_alloc_size_t; typedef size_t png_alloc_size_t;
#endif #endif
/* Prior to 1.6.0 libpng offered limited support for Microsoft C compiler /* Prior to 1.6.0 libpng offered limited support for Microsoft C compiler
...@@ -617,8 +618,8 @@ typedef char * png_charp; ...@@ -617,8 +618,8 @@ typedef char * png_charp;
typedef const char * png_const_charp; typedef const char * png_const_charp;
typedef png_fixed_point * png_fixed_point_p; typedef png_fixed_point * png_fixed_point_p;
typedef const png_fixed_point * png_const_fixed_point_p; typedef const png_fixed_point * png_const_fixed_point_p;
typedef png_size_t * png_size_tp; typedef size_t * png_size_tp;
typedef const png_size_t * png_const_size_tp; typedef const size_t * png_const_size_tp;
#ifdef PNG_STDIO_SUPPORTED #ifdef PNG_STDIO_SUPPORTED
typedef FILE * png_FILE_p; typedef FILE * png_FILE_p;
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
* However, the following notice accompanied the original version of this * However, the following notice accompanied the original version of this
* file and, per its terms, should not be removed: * file and, per its terms, should not be removed:
* *
* Last changed in libpng 1.6.26 [October 20, 2016] * Last changed in libpng 1.6.31 [July 27, 2017]
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
...@@ -191,7 +191,7 @@ png_format_number(png_const_charp start, png_charp end, int format, ...@@ -191,7 +191,7 @@ png_format_number(png_const_charp start, png_charp end, int format,
case PNG_NUMBER_FORMAT_02u: case PNG_NUMBER_FORMAT_02u:
/* Expects at least 2 digits. */ /* Expects at least 2 digits. */
mincount = 2; mincount = 2;
/* FALL THROUGH */ /* FALLTHROUGH */
case PNG_NUMBER_FORMAT_u: case PNG_NUMBER_FORMAT_u:
*--end = digits[number % 10]; *--end = digits[number % 10];
...@@ -201,7 +201,7 @@ png_format_number(png_const_charp start, png_charp end, int format, ...@@ -201,7 +201,7 @@ png_format_number(png_const_charp start, png_charp end, int format,
case PNG_NUMBER_FORMAT_02x: case PNG_NUMBER_FORMAT_02x:
/* This format expects at least two digits */ /* This format expects at least two digits */
mincount = 2; mincount = 2;
/* FALL THROUGH */ /* FALLTHROUGH */
case PNG_NUMBER_FORMAT_x: case PNG_NUMBER_FORMAT_x:
*--end = digits[number & 0xf]; *--end = digits[number & 0xf];
......
...@@ -28,9 +28,9 @@ ...@@ -28,9 +28,9 @@
* License version 2 only, as published by the Free Software Foundation. * License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this * However, the following notice accompanied the original version of this
* file and, per its terms, should not be removed: * file and, per its terms, should not be removed:
*
* Last changed in libpng 1.6.26 [October 20, 2016] * Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
...@@ -54,7 +54,7 @@ png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr, ...@@ -54,7 +54,7 @@ png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr,
return(0); return(0);
} }
png_size_t PNGAPI size_t PNGAPI
png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr) png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
...@@ -395,7 +395,7 @@ png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr) ...@@ -395,7 +395,7 @@ png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
static png_fixed_point static png_fixed_point
png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns) png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns)
{ {
/* Convert from metres * 1,000,000 to inches * 100,000, meters to /* Convert from meters * 1,000,000 to inches * 100,000, meters to
* inches is simply *(100/2.54), so we want *(10/2.54) == 500/127. * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
* Notice that this can overflow - a warning is output and 0 is * Notice that this can overflow - a warning is output and 0 is
* returned. * returned.
...@@ -769,8 +769,7 @@ png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr, ...@@ -769,8 +769,7 @@ png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
if (png_ptr != NULL && info_ptr != NULL && if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_iCCP) != 0 && (info_ptr->valid & PNG_INFO_iCCP) != 0 &&
name != NULL && compression_type != NULL && profile != NULL && name != NULL && profile != NULL && proflen != NULL)
proflen != NULL)
{ {
*name = info_ptr->iccp_name; *name = info_ptr->iccp_name;
*profile = info_ptr->iccp_profile; *profile = info_ptr->iccp_profile;
...@@ -778,11 +777,13 @@ png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr, ...@@ -778,11 +777,13 @@ png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
/* This is somewhat irrelevant since the profile data returned has /* This is somewhat irrelevant since the profile data returned has
* actually been uncompressed. * actually been uncompressed.
*/ */
*compression_type = PNG_COMPRESSION_TYPE_BASE; if (compression_type != NULL)
*compression_type = PNG_COMPRESSION_TYPE_BASE;
return (PNG_INFO_iCCP); return (PNG_INFO_iCCP);
} }
return (0); return (0);
} }
#endif #endif
...@@ -801,6 +802,35 @@ png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr, ...@@ -801,6 +802,35 @@ png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
} }
#endif #endif
#ifdef PNG_eXIf_SUPPORTED
png_uint_32 PNGAPI
png_get_eXIf(png_const_structrp png_ptr, png_inforp info_ptr,
png_bytep *exif)
{
png_warning(png_ptr, "png_get_eXIf does not work; use png_get_eXIf_1");
PNG_UNUSED(info_ptr)
PNG_UNUSED(exif)
return 0;
}
png_uint_32 PNGAPI
png_get_eXIf_1(png_const_structrp png_ptr, png_const_inforp info_ptr,
png_uint_32 *num_exif, png_bytep *exif)
{
png_debug1(1, "in %s retrieval function", "eXIf");
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_eXIf) != 0 && exif != NULL)
{
*num_exif = info_ptr->num_exif;
*exif = info_ptr->exif;
return (PNG_INFO_eXIf);
}
return (0);
}
#endif
#ifdef PNG_hIST_SUPPORTED #ifdef PNG_hIST_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr, png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
...@@ -1163,7 +1193,7 @@ png_get_user_chunk_ptr(png_const_structrp png_ptr) ...@@ -1163,7 +1193,7 @@ png_get_user_chunk_ptr(png_const_structrp png_ptr)
} }
#endif #endif
png_size_t PNGAPI size_t PNGAPI
png_get_compression_buffer_size(png_const_structrp png_ptr) png_get_compression_buffer_size(png_const_structrp png_ptr)
{ {
if (png_ptr == NULL) if (png_ptr == NULL)
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
* However, the following notice accompanied the original version of this * However, the following notice accompanied the original version of this
* file and, per its terms, should not be removed: * file and, per its terms, should not be removed:
* *
* Last changed in libpng 1.6.1 [March 28, 2013] * Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 1998-2002,2004,2006-2013 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2013,2018 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
...@@ -83,10 +83,10 @@ ...@@ -83,10 +83,10 @@
struct png_info_def struct png_info_def
{ {
/* The following are necessary for every PNG file */ /* The following are necessary for every PNG file */
png_uint_32 width; /* width of image in pixels (from IHDR) */ png_uint_32 width; /* width of image in pixels (from IHDR) */
png_uint_32 height; /* height of image in pixels (from IHDR) */ png_uint_32 height; /* height of image in pixels (from IHDR) */
png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */ png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
png_size_t rowbytes; /* bytes needed to hold an untransformed row */ size_t rowbytes; /* bytes needed to hold an untransformed row */
png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */ png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */ png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
png_uint_16 num_trans; /* number of transparent palette color (tRNS) */ png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
...@@ -213,6 +213,14 @@ defined(PNG_READ_BACKGROUND_SUPPORTED) ...@@ -213,6 +213,14 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */ png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
#endif #endif
#ifdef PNG_eXIf_SUPPORTED
int num_exif; /* Added at libpng-1.6.31 */
png_bytep exif;
# ifdef PNG_READ_eXIf_SUPPORTED
png_bytep eXIf_buf; /* Added at libpng-1.6.32 */
# endif
#endif
#ifdef PNG_hIST_SUPPORTED #ifdef PNG_hIST_SUPPORTED
/* The hIST chunk contains the relative frequency or importance of the /* The hIST chunk contains the relative frequency or importance of the
* various palette entries, so that a viewer can intelligently select a * various palette entries, so that a viewer can intelligently select a
...@@ -267,7 +275,7 @@ defined(PNG_READ_BACKGROUND_SUPPORTED) ...@@ -267,7 +275,7 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
/* The sCAL chunk describes the actual physical dimensions of the /* The sCAL chunk describes the actual physical dimensions of the
* subject matter of the graphic. The chunk contains a unit specification * subject matter of the graphic. The chunk contains a unit specification
* a byte value, and two ASCII strings representing floating-point * a byte value, and two ASCII strings representing floating-point
* values. The values are width and height corresponsing to one pixel * values. The values are width and height corresponding to one pixel
* in the image. Data values are valid if (valid & PNG_INFO_sCAL) is * in the image. Data values are valid if (valid & PNG_INFO_sCAL) is
* non-zero. * non-zero.
*/ */
......
/* /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file and, per its terms, should not be removed:
*
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as * under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this * published by the Free Software Foundation. Oracle designates this
...@@ -33,9 +38,9 @@ ...@@ -33,9 +38,9 @@
* file and, per its terms, should not be removed: * file and, per its terms, should not be removed:
*/ */
/* libpng version 1.6.28, January 5, 2017 */ /* libpng version 1.6.35, July 15, 2018 */
/* Copyright (c) 1998-2016 Glenn Randers-Pehrson */ /* Copyright (c) 1998-2018 Glenn Randers-Pehrson */
/* This code is released under the libpng license. */ /* This code is released under the libpng license. */
/* For conditions of distribution and use, see the disclaimer */ /* For conditions of distribution and use, see the disclaimer */
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
* However, the following notice accompanied the original version of this * However, the following notice accompanied the original version of this
* file and, per its terms, should not be removed: * file and, per its terms, should not be removed:
* *
* Last changed in libpng 1.6.24 [August 4, 2016] * Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
...@@ -62,7 +62,7 @@ if (png_ptr->buffer_size < N) \ ...@@ -62,7 +62,7 @@ if (png_ptr->buffer_size < N) \
void PNGAPI void PNGAPI
png_process_data(png_structrp png_ptr, png_inforp info_ptr, png_process_data(png_structrp png_ptr, png_inforp info_ptr,
png_bytep buffer, png_size_t buffer_size) png_bytep buffer, size_t buffer_size)
{ {
if (png_ptr == NULL || info_ptr == NULL) if (png_ptr == NULL || info_ptr == NULL)
return; return;
...@@ -75,7 +75,7 @@ png_process_data(png_structrp png_ptr, png_inforp info_ptr, ...@@ -75,7 +75,7 @@ png_process_data(png_structrp png_ptr, png_inforp info_ptr,
} }
} }
png_size_t PNGAPI size_t PNGAPI
png_process_data_pause(png_structrp png_ptr, int save) png_process_data_pause(png_structrp png_ptr, int save)
{ {
if (png_ptr != NULL) if (png_ptr != NULL)
...@@ -88,7 +88,7 @@ png_process_data_pause(png_structrp png_ptr, int save) ...@@ -88,7 +88,7 @@ png_process_data_pause(png_structrp png_ptr, int save)
else else
{ {
/* This includes any pending saved bytes: */ /* This includes any pending saved bytes: */
png_size_t remaining = png_ptr->buffer_size; size_t remaining = png_ptr->buffer_size;
png_ptr->buffer_size = 0; png_ptr->buffer_size = 0;
/* So subtract the saved buffer size, unless all the data /* So subtract the saved buffer size, unless all the data
...@@ -161,8 +161,8 @@ png_process_some_data(png_structrp png_ptr, png_inforp info_ptr) ...@@ -161,8 +161,8 @@ png_process_some_data(png_structrp png_ptr, png_inforp info_ptr)
void /* PRIVATE */ void /* PRIVATE */
png_push_read_sig(png_structrp png_ptr, png_inforp info_ptr) png_push_read_sig(png_structrp png_ptr, png_inforp info_ptr)
{ {
png_size_t num_checked = png_ptr->sig_bytes, /* SAFE, does not exceed 8 */ size_t num_checked = png_ptr->sig_bytes; /* SAFE, does not exceed 8 */
num_to_check = 8 - num_checked; size_t num_to_check = 8 - num_checked;
if (png_ptr->buffer_size < num_to_check) if (png_ptr->buffer_size < num_to_check)
{ {
...@@ -217,6 +217,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr) ...@@ -217,6 +217,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
png_crc_read(png_ptr, chunk_tag, 4); png_crc_read(png_ptr, chunk_tag, 4);
png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag); png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag);
png_check_chunk_name(png_ptr, png_ptr->chunk_name); png_check_chunk_name(png_ptr, png_ptr->chunk_name);
png_check_chunk_length(png_ptr, png_ptr->push_length);
png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
} }
...@@ -445,7 +446,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr) ...@@ -445,7 +446,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
} }
void PNGCBAPI void PNGCBAPI
png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length) png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, size_t length)
{ {
png_bytep ptr; png_bytep ptr;
...@@ -455,7 +456,7 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length) ...@@ -455,7 +456,7 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
ptr = buffer; ptr = buffer;
if (png_ptr->save_buffer_size != 0) if (png_ptr->save_buffer_size != 0)
{ {
png_size_t save_size; size_t save_size;
if (length < png_ptr->save_buffer_size) if (length < png_ptr->save_buffer_size)
save_size = length; save_size = length;
...@@ -472,7 +473,7 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length) ...@@ -472,7 +473,7 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
} }
if (length != 0 && png_ptr->current_buffer_size != 0) if (length != 0 && png_ptr->current_buffer_size != 0)
{ {
png_size_t save_size; size_t save_size;
if (length < png_ptr->current_buffer_size) if (length < png_ptr->current_buffer_size)
save_size = length; save_size = length;
...@@ -494,7 +495,7 @@ png_push_save_buffer(png_structrp png_ptr) ...@@ -494,7 +495,7 @@ png_push_save_buffer(png_structrp png_ptr)
{ {
if (png_ptr->save_buffer_ptr != png_ptr->save_buffer) if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
{ {
png_size_t i, istop; size_t i, istop;
png_bytep sp; png_bytep sp;
png_bytep dp; png_bytep dp;
...@@ -509,7 +510,7 @@ png_push_save_buffer(png_structrp png_ptr) ...@@ -509,7 +510,7 @@ png_push_save_buffer(png_structrp png_ptr)
if (png_ptr->save_buffer_size + png_ptr->current_buffer_size > if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
png_ptr->save_buffer_max) png_ptr->save_buffer_max)
{ {
png_size_t new_max; size_t new_max;
png_bytep old_buffer; png_bytep old_buffer;
if (png_ptr->save_buffer_size > PNG_SIZE_MAX - if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
...@@ -521,7 +522,7 @@ png_push_save_buffer(png_structrp png_ptr) ...@@ -521,7 +522,7 @@ png_push_save_buffer(png_structrp png_ptr)
new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256; new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
old_buffer = png_ptr->save_buffer; old_buffer = png_ptr->save_buffer;
png_ptr->save_buffer = (png_bytep)png_malloc_warn(png_ptr, png_ptr->save_buffer = (png_bytep)png_malloc_warn(png_ptr,
(png_size_t)new_max); (size_t)new_max);
if (png_ptr->save_buffer == NULL) if (png_ptr->save_buffer == NULL)
{ {
...@@ -549,7 +550,7 @@ png_push_save_buffer(png_structrp png_ptr) ...@@ -549,7 +550,7 @@ png_push_save_buffer(png_structrp png_ptr)
void /* PRIVATE */ void /* PRIVATE */
png_push_restore_buffer(png_structrp png_ptr, png_bytep buffer, png_push_restore_buffer(png_structrp png_ptr, png_bytep buffer,
png_size_t buffer_length) size_t buffer_length)
{ {
png_ptr->current_buffer = buffer; png_ptr->current_buffer = buffer;
png_ptr->current_buffer_size = buffer_length; png_ptr->current_buffer_size = buffer_length;
...@@ -589,7 +590,7 @@ png_push_read_IDAT(png_structrp png_ptr) ...@@ -589,7 +590,7 @@ png_push_read_IDAT(png_structrp png_ptr)
if (png_ptr->idat_size != 0 && png_ptr->save_buffer_size != 0) if (png_ptr->idat_size != 0 && png_ptr->save_buffer_size != 0)
{ {
png_size_t save_size = png_ptr->save_buffer_size; size_t save_size = png_ptr->save_buffer_size;
png_uint_32 idat_size = png_ptr->idat_size; png_uint_32 idat_size = png_ptr->idat_size;
/* We want the smaller of 'idat_size' and 'current_buffer_size', but they /* We want the smaller of 'idat_size' and 'current_buffer_size', but they
...@@ -599,7 +600,7 @@ png_push_read_IDAT(png_structrp png_ptr) ...@@ -599,7 +600,7 @@ png_push_read_IDAT(png_structrp png_ptr)
* will break on either 16-bit or 64-bit platforms. * will break on either 16-bit or 64-bit platforms.
*/ */
if (idat_size < save_size) if (idat_size < save_size)
save_size = (png_size_t)idat_size; save_size = (size_t)idat_size;
else else
idat_size = (png_uint_32)save_size; idat_size = (png_uint_32)save_size;
...@@ -616,7 +617,7 @@ png_push_read_IDAT(png_structrp png_ptr) ...@@ -616,7 +617,7 @@ png_push_read_IDAT(png_structrp png_ptr)
if (png_ptr->idat_size != 0 && png_ptr->current_buffer_size != 0) if (png_ptr->idat_size != 0 && png_ptr->current_buffer_size != 0)
{ {
png_size_t save_size = png_ptr->current_buffer_size; size_t save_size = png_ptr->current_buffer_size;
png_uint_32 idat_size = png_ptr->idat_size; png_uint_32 idat_size = png_ptr->idat_size;
/* We want the smaller of 'idat_size' and 'current_buffer_size', but they /* We want the smaller of 'idat_size' and 'current_buffer_size', but they
...@@ -625,7 +626,7 @@ png_push_read_IDAT(png_structrp png_ptr) ...@@ -625,7 +626,7 @@ png_push_read_IDAT(png_structrp png_ptr)
* larger - this cannot overflow. * larger - this cannot overflow.
*/ */
if (idat_size < save_size) if (idat_size < save_size)
save_size = (png_size_t)idat_size; save_size = (size_t)idat_size;
else else
idat_size = (png_uint_32)save_size; idat_size = (png_uint_32)save_size;
...@@ -652,7 +653,7 @@ png_push_read_IDAT(png_structrp png_ptr) ...@@ -652,7 +653,7 @@ png_push_read_IDAT(png_structrp png_ptr)
void /* PRIVATE */ void /* PRIVATE */
png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer, png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer,
png_size_t buffer_length) size_t buffer_length)
{ {
/* The caller checks for a non-zero buffer length. */ /* The caller checks for a non-zero buffer length. */
if (!(buffer_length > 0) || buffer == NULL) if (!(buffer_length > 0) || buffer == NULL)
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
* However, the following notice accompanied the original version of this * However, the following notice accompanied the original version of this
* file and, per its terms, should not be removed: * file and, per its terms, should not be removed:
* *
* Last changed in libpng 1.6.26 [October 20, 2016] * Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
...@@ -63,7 +63,9 @@ ...@@ -63,7 +63,9 @@
* Windows/Visual Studio) there is no effect; the OS specific tests below are * Windows/Visual Studio) there is no effect; the OS specific tests below are
* still required (as of 2011-05-02.) * still required (as of 2011-05-02.)
*/ */
#define _POSIX_SOURCE 1 /* Just the POSIX 1003.1 and C89 APIs */ #ifndef _POSIX_SOURCE
# define _POSIX_SOURCE 1 /* Just the POSIX 1003.1 and C89 APIs */
#endif
#ifndef PNG_VERSION_INFO_ONLY #ifndef PNG_VERSION_INFO_ONLY
/* Standard library headers not required by png.h: */ /* Standard library headers not required by png.h: */
...@@ -218,6 +220,56 @@ ...@@ -218,6 +220,56 @@
# endif # endif
#endif #endif
#ifndef PNG_POWERPC_VSX_OPT
# if defined(__PPC64__) && defined(__ALTIVEC__) && defined(__VSX__)
# define PNG_POWERPC_VSX_OPT 2
# else
# define PNG_POWERPC_VSX_OPT 0
# endif
#endif
#ifndef PNG_INTEL_SSE_OPT
# ifdef PNG_INTEL_SSE
/* Only check for SSE if the build configuration has been modified to
* enable SSE optimizations. This means that these optimizations will
* be off by default. See contrib/intel for more details.
*/
# if defined(__SSE4_1__) || defined(__AVX__) || defined(__SSSE3__) || \
defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \
(defined(_M_IX86_FP) && _M_IX86_FP >= 2)
# define PNG_INTEL_SSE_OPT 1
# else
# define PNG_INTEL_SSE_OPT 0
# endif
# else
# define PNG_INTEL_SSE_OPT 0
# endif
#endif
#if PNG_INTEL_SSE_OPT > 0
# ifndef PNG_INTEL_SSE_IMPLEMENTATION
# if defined(__SSE4_1__) || defined(__AVX__)
/* We are not actually using AVX, but checking for AVX is the best
way we can detect SSE4.1 and SSSE3 on MSVC.
*/
# define PNG_INTEL_SSE_IMPLEMENTATION 3
# elif defined(__SSSE3__)
# define PNG_INTEL_SSE_IMPLEMENTATION 2
# elif defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \
(defined(_M_IX86_FP) && _M_IX86_FP >= 2)
# define PNG_INTEL_SSE_IMPLEMENTATION 1
# else
# define PNG_INTEL_SSE_IMPLEMENTATION 0
# endif
# endif
# if PNG_INTEL_SSE_IMPLEMENTATION > 0
# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_sse2
# endif
#else
# define PNG_INTEL_SSE_IMPLEMENTATION 0
#endif
#if PNG_MIPS_MSA_OPT > 0 #if PNG_MIPS_MSA_OPT > 0
# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_msa # define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_msa
# ifndef PNG_MIPS_MSA_IMPLEMENTATION # ifndef PNG_MIPS_MSA_IMPLEMENTATION
...@@ -238,6 +290,13 @@ ...@@ -238,6 +290,13 @@
# endif # endif
#endif /* PNG_MIPS_MSA_OPT > 0 */ #endif /* PNG_MIPS_MSA_OPT > 0 */
#ifdef PNG_POWERPC_VSX_API_SUPPORTED
#if PNG_POWERPC_VSX_OPT > 0
# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_vsx
# define PNG_POWERPC_VSX_IMPLEMENTATION 1
#endif
#endif
/* Is this a build of a DLL where compilation of the object modules requires /* Is this a build of a DLL where compilation of the object modules requires
* different preprocessor settings to those required for a simple library? If * different preprocessor settings to those required for a simple library? If
...@@ -431,6 +490,21 @@ ...@@ -431,6 +490,21 @@
# define png_fixed_error(s1,s2) png_err(s1) # define png_fixed_error(s1,s2) png_err(s1)
#endif #endif
/* Some fixed point APIs are still required even if not exported because
* they get used by the corresponding floating point APIs. This magic
* deals with this:
*/
#ifdef PNG_FIXED_POINT_SUPPORTED
# define PNGFAPI PNGAPI
#else
# define PNGFAPI /* PRIVATE */
#endif
#ifndef PNG_VERSION_INFO_ONLY
/* Other defines specific to compilers can go here. Try to keep
* them inside an appropriate ifdef/endif pair for portability.
*/
/* C allows up-casts from (void*) to any pointer and (const void*) to any /* C allows up-casts from (void*) to any pointer and (const void*) to any
* pointer to a const object. C++ regards this as a type error and requires an * pointer to a const object. C++ regards this as a type error and requires an
* explicit, static, cast and provides the static_cast<> rune to ensure that * explicit, static, cast and provides the static_cast<> rune to ensure that
...@@ -445,25 +519,20 @@ ...@@ -445,25 +519,20 @@
static_cast<type>(static_cast<const void*>(value)) static_cast<type>(static_cast<const void*>(value))
#else #else
# define png_voidcast(type, value) (value) # define png_voidcast(type, value) (value)
# define png_constcast(type, value) ((type)(value)) # ifdef _WIN64
# ifdef __GNUC__
typedef unsigned long long png_ptruint;
# else
typedef unsigned __int64 png_ptruint;
# endif
# else
typedef unsigned long png_ptruint;
# endif
# define png_constcast(type, value) ((type)(png_ptruint)(const void*)(value))
# define png_aligncast(type, value) ((void*)(value)) # define png_aligncast(type, value) ((void*)(value))
# define png_aligncastconst(type, value) ((const void*)(value)) # define png_aligncastconst(type, value) ((const void*)(value))
#endif /* __cplusplus */ #endif /* __cplusplus */
/* Some fixed point APIs are still required even if not exported because
* they get used by the corresponding floating point APIs. This magic
* deals with this:
*/
#ifdef PNG_FIXED_POINT_SUPPORTED
# define PNGFAPI PNGAPI
#else
# define PNGFAPI /* PRIVATE */
#endif
#ifndef PNG_VERSION_INFO_ONLY
/* Other defines specific to compilers can go here. Try to keep
* them inside an appropriate ifdef/endif pair for portability.
*/
#if defined(PNG_FLOATING_POINT_SUPPORTED) ||\ #if defined(PNG_FLOATING_POINT_SUPPORTED) ||\
defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)
/* png.c requires the following ANSI-C constants if the conversion of /* png.c requires the following ANSI-C constants if the conversion of
...@@ -695,8 +764,8 @@ ...@@ -695,8 +764,8 @@
/* Added to libpng-1.2.6 JB */ /* Added to libpng-1.2.6 JB */
#define PNG_ROWBYTES(pixel_bits, width) \ #define PNG_ROWBYTES(pixel_bits, width) \
((pixel_bits) >= 8 ? \ ((pixel_bits) >= 8 ? \
((png_size_t)(width) * (((png_size_t)(pixel_bits)) >> 3)) : \ ((size_t)(width) * (((size_t)(pixel_bits)) >> 3)) : \
(( ((png_size_t)(width) * ((png_size_t)(pixel_bits))) + 7) >> 3) ) (( ((size_t)(width) * ((size_t)(pixel_bits))) + 7) >> 3) )
/* This returns the number of trailing bits in the last byte of a row, 0 if the /* This returns the number of trailing bits in the last byte of a row, 0 if the
* last byte is completely full of pixels. It is, in principle, (pixel_bits x * last byte is completely full of pixels. It is, in principle, (pixel_bits x
...@@ -809,6 +878,7 @@ ...@@ -809,6 +878,7 @@
#define png_PLTE PNG_U32( 80, 76, 84, 69) #define png_PLTE PNG_U32( 80, 76, 84, 69)
#define png_bKGD PNG_U32( 98, 75, 71, 68) #define png_bKGD PNG_U32( 98, 75, 71, 68)
#define png_cHRM PNG_U32( 99, 72, 82, 77) #define png_cHRM PNG_U32( 99, 72, 82, 77)
#define png_eXIf PNG_U32(101, 88, 73, 102) /* registered July 2017 */
#define png_fRAc PNG_U32(102, 82, 65, 99) /* registered, not defined */ #define png_fRAc PNG_U32(102, 82, 65, 99) /* registered, not defined */
#define png_gAMA PNG_U32(103, 65, 77, 65) #define png_gAMA PNG_U32(103, 65, 77, 65)
#define png_gIFg PNG_U32(103, 73, 70, 103) #define png_gIFg PNG_U32(103, 73, 70, 103)
...@@ -883,7 +953,7 @@ ...@@ -883,7 +953,7 @@
* PNG files the -I directives must match. * PNG files the -I directives must match.
* *
* The most likely explanation is that you passed a -I in CFLAGS. This will * The most likely explanation is that you passed a -I in CFLAGS. This will
* not work; all the preprocessor directories and in particular all the -I * not work; all the preprocessor directives and in particular all the -I
* directives must be in CPPFLAGS. * directives must be in CPPFLAGS.
*/ */
#endif #endif
...@@ -1012,15 +1082,15 @@ PNG_INTERNAL_FUNCTION(void,png_zfree,(voidpf png_ptr, voidpf ptr),PNG_EMPTY); ...@@ -1012,15 +1082,15 @@ PNG_INTERNAL_FUNCTION(void,png_zfree,(voidpf png_ptr, voidpf ptr),PNG_EMPTY);
*/ */
PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_read_data,(png_structp png_ptr, PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_read_data,(png_structp png_ptr,
png_bytep data, png_size_t length),PNG_EMPTY); png_bytep data, size_t length),PNG_EMPTY);
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_push_fill_buffer,(png_structp png_ptr, PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_push_fill_buffer,(png_structp png_ptr,
png_bytep buffer, png_size_t length),PNG_EMPTY); png_bytep buffer, size_t length),PNG_EMPTY);
#endif #endif
PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_write_data,(png_structp png_ptr, PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_write_data,(png_structp png_ptr,
png_bytep data, png_size_t length),PNG_EMPTY); png_bytep data, size_t length),PNG_EMPTY);
#ifdef PNG_WRITE_FLUSH_SUPPORTED #ifdef PNG_WRITE_FLUSH_SUPPORTED
# ifdef PNG_STDIO_SUPPORTED # ifdef PNG_STDIO_SUPPORTED
...@@ -1034,7 +1104,7 @@ PNG_INTERNAL_FUNCTION(void,png_reset_crc,(png_structrp png_ptr),PNG_EMPTY); ...@@ -1034,7 +1104,7 @@ PNG_INTERNAL_FUNCTION(void,png_reset_crc,(png_structrp png_ptr),PNG_EMPTY);
/* Write the "data" buffer to whatever output you are using */ /* Write the "data" buffer to whatever output you are using */
PNG_INTERNAL_FUNCTION(void,png_write_data,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_write_data,(png_structrp png_ptr,
png_const_bytep data, png_size_t length),PNG_EMPTY); png_const_bytep data, size_t length),PNG_EMPTY);
/* Read and check the PNG file signature */ /* Read and check the PNG file signature */
PNG_INTERNAL_FUNCTION(void,png_read_sig,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_read_sig,(png_structrp png_ptr,
...@@ -1046,7 +1116,7 @@ PNG_INTERNAL_FUNCTION(png_uint_32,png_read_chunk_header,(png_structrp png_ptr), ...@@ -1046,7 +1116,7 @@ PNG_INTERNAL_FUNCTION(png_uint_32,png_read_chunk_header,(png_structrp png_ptr),
/* Read data from whatever input you are using into the "data" buffer */ /* Read data from whatever input you are using into the "data" buffer */
PNG_INTERNAL_FUNCTION(void,png_read_data,(png_structrp png_ptr, png_bytep data, PNG_INTERNAL_FUNCTION(void,png_read_data,(png_structrp png_ptr, png_bytep data,
png_size_t length),PNG_EMPTY); size_t length),PNG_EMPTY);
/* Read bytes into buf, and update png_ptr->crc */ /* Read bytes into buf, and update png_ptr->crc */
PNG_INTERNAL_FUNCTION(void,png_crc_read,(png_structrp png_ptr, png_bytep buf, PNG_INTERNAL_FUNCTION(void,png_crc_read,(png_structrp png_ptr, png_bytep buf,
...@@ -1064,7 +1134,7 @@ PNG_INTERNAL_FUNCTION(int,png_crc_error,(png_structrp png_ptr),PNG_EMPTY); ...@@ -1064,7 +1134,7 @@ PNG_INTERNAL_FUNCTION(int,png_crc_error,(png_structrp png_ptr),PNG_EMPTY);
* since this is the maximum buffer size we can specify. * since this is the maximum buffer size we can specify.
*/ */
PNG_INTERNAL_FUNCTION(void,png_calculate_crc,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_calculate_crc,(png_structrp png_ptr,
png_const_bytep ptr, png_size_t length),PNG_EMPTY); png_const_bytep ptr, size_t length),PNG_EMPTY);
#ifdef PNG_WRITE_FLUSH_SUPPORTED #ifdef PNG_WRITE_FLUSH_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_flush,(png_structrp png_ptr),PNG_EMPTY); PNG_INTERNAL_FUNCTION(void,png_flush,(png_structrp png_ptr),PNG_EMPTY);
...@@ -1109,6 +1179,11 @@ PNG_INTERNAL_FUNCTION(void,png_write_sRGB,(png_structrp png_ptr, ...@@ -1109,6 +1179,11 @@ PNG_INTERNAL_FUNCTION(void,png_write_sRGB,(png_structrp png_ptr,
int intent),PNG_EMPTY); int intent),PNG_EMPTY);
#endif #endif
#ifdef PNG_WRITE_eXIf_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_write_eXIf,(png_structrp png_ptr,
png_bytep exif, int num_exif),PNG_EMPTY);
#endif
#ifdef PNG_WRITE_iCCP_SUPPORTED #ifdef PNG_WRITE_iCCP_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_write_iCCP,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_write_iCCP,(png_structrp png_ptr,
png_const_charp name, png_const_bytep profile), PNG_EMPTY); png_const_charp name, png_const_bytep profile), PNG_EMPTY);
...@@ -1142,7 +1217,7 @@ PNG_INTERNAL_FUNCTION(void,png_write_hIST,(png_structrp png_ptr, ...@@ -1142,7 +1217,7 @@ PNG_INTERNAL_FUNCTION(void,png_write_hIST,(png_structrp png_ptr,
/* Chunks that have keywords */ /* Chunks that have keywords */
#ifdef PNG_WRITE_tEXt_SUPPORTED #ifdef PNG_WRITE_tEXt_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_write_tEXt,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_write_tEXt,(png_structrp png_ptr,
png_const_charp key, png_const_charp text, png_size_t text_len),PNG_EMPTY); png_const_charp key, png_const_charp text, size_t text_len),PNG_EMPTY);
#endif #endif
#ifdef PNG_WRITE_zTXt_SUPPORTED #ifdef PNG_WRITE_zTXt_SUPPORTED
...@@ -1284,6 +1359,38 @@ PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_msa,(png_row_infop ...@@ -1284,6 +1359,38 @@ PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_msa,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
#endif #endif
#if PNG_POWERPC_VSX_OPT > 0
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_up_vsx,(png_row_infop row_info,
png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_vsx,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_vsx,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_vsx,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_vsx,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_vsx,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_vsx,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
#endif
#if PNG_INTEL_SSE_IMPLEMENTATION > 0
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_sse2,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_sse2,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_sse2,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_sse2,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_sse2,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_sse2,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
#endif
/* Choose the best filter to use and filter the row data */ /* Choose the best filter to use and filter the row data */
PNG_INTERNAL_FUNCTION(void,png_write_find_filter,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_write_find_filter,(png_structrp png_ptr,
png_row_infop row_info),PNG_EMPTY); png_row_infop row_info),PNG_EMPTY);
...@@ -1376,6 +1483,11 @@ PNG_INTERNAL_FUNCTION(void,png_handle_cHRM,(png_structrp png_ptr, ...@@ -1376,6 +1483,11 @@ PNG_INTERNAL_FUNCTION(void,png_handle_cHRM,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
#endif #endif
#ifdef PNG_READ_eXIf_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_eXIf,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
#endif
#ifdef PNG_READ_gAMA_SUPPORTED #ifdef PNG_READ_gAMA_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_gAMA,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_handle_gAMA,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
...@@ -1451,8 +1563,11 @@ PNG_INTERNAL_FUNCTION(void,png_handle_zTXt,(png_structrp png_ptr, ...@@ -1451,8 +1563,11 @@ PNG_INTERNAL_FUNCTION(void,png_handle_zTXt,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY); png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
#endif #endif
PNG_INTERNAL_FUNCTION(void,png_check_chunk_name,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_check_chunk_name,(png_const_structrp png_ptr,
png_uint_32 chunk_name),PNG_EMPTY); const png_uint_32 chunk_name),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_check_chunk_length,(png_const_structrp png_ptr,
const png_uint_32 chunk_length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_unknown,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_handle_unknown,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length, int keep),PNG_EMPTY); png_inforp info_ptr, png_uint_32 length, int keep),PNG_EMPTY);
...@@ -1495,10 +1610,10 @@ PNG_INTERNAL_FUNCTION(void,png_push_check_crc,(png_structrp png_ptr),PNG_EMPTY); ...@@ -1495,10 +1610,10 @@ PNG_INTERNAL_FUNCTION(void,png_push_check_crc,(png_structrp png_ptr),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_save_buffer,(png_structrp png_ptr), PNG_INTERNAL_FUNCTION(void,png_push_save_buffer,(png_structrp png_ptr),
PNG_EMPTY); PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_restore_buffer,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_push_restore_buffer,(png_structrp png_ptr,
png_bytep buffer, png_size_t buffer_length),PNG_EMPTY); png_bytep buffer, size_t buffer_length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_read_IDAT,(png_structrp png_ptr),PNG_EMPTY); PNG_INTERNAL_FUNCTION(void,png_push_read_IDAT,(png_structrp png_ptr),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_process_IDAT_data,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_process_IDAT_data,(png_structrp png_ptr,
png_bytep buffer, png_size_t buffer_length),PNG_EMPTY); png_bytep buffer, size_t buffer_length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_process_row,(png_structrp png_ptr), PNG_INTERNAL_FUNCTION(void,png_push_process_row,(png_structrp png_ptr),
PNG_EMPTY); PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_handle_unknown,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_push_handle_unknown,(png_structrp png_ptr,
...@@ -1768,13 +1883,13 @@ PNG_INTERNAL_FUNCTION(void,png_chunk_report,(png_const_structrp png_ptr, ...@@ -1768,13 +1883,13 @@ PNG_INTERNAL_FUNCTION(void,png_chunk_report,(png_const_structrp png_ptr,
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_ascii_from_fp,(png_const_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_ascii_from_fp,(png_const_structrp png_ptr,
png_charp ascii, png_size_t size, double fp, unsigned int precision), png_charp ascii, size_t size, double fp, unsigned int precision),
PNG_EMPTY); PNG_EMPTY);
#endif /* FLOATING_POINT */ #endif /* FLOATING_POINT */
#ifdef PNG_FIXED_POINT_SUPPORTED #ifdef PNG_FIXED_POINT_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_ascii_from_fixed,(png_const_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_ascii_from_fixed,(png_const_structrp png_ptr,
png_charp ascii, png_size_t size, png_fixed_point fp),PNG_EMPTY); png_charp ascii, size_t size, png_fixed_point fp),PNG_EMPTY);
#endif /* FIXED_POINT */ #endif /* FIXED_POINT */
#endif /* sCAL */ #endif /* sCAL */
...@@ -1867,7 +1982,7 @@ PNG_INTERNAL_FUNCTION(void,png_ascii_from_fixed,(png_const_structrp png_ptr, ...@@ -1867,7 +1982,7 @@ PNG_INTERNAL_FUNCTION(void,png_ascii_from_fixed,(png_const_structrp png_ptr,
* the problem character.) This has not been tested within libpng. * the problem character.) This has not been tested within libpng.
*/ */
PNG_INTERNAL_FUNCTION(int,png_check_fp_number,(png_const_charp string, PNG_INTERNAL_FUNCTION(int,png_check_fp_number,(png_const_charp string,
png_size_t size, int *statep, png_size_tp whereami),PNG_EMPTY); size_t size, int *statep, png_size_tp whereami),PNG_EMPTY);
/* This is the same but it checks a complete string and returns true /* This is the same but it checks a complete string and returns true
* only if it just contains a floating point number. As of 1.5.4 this * only if it just contains a floating point number. As of 1.5.4 this
...@@ -1876,7 +1991,7 @@ PNG_INTERNAL_FUNCTION(int,png_check_fp_number,(png_const_charp string, ...@@ -1876,7 +1991,7 @@ PNG_INTERNAL_FUNCTION(int,png_check_fp_number,(png_const_charp string,
* for negative or zero values using the sticky flag. * for negative or zero values using the sticky flag.
*/ */
PNG_INTERNAL_FUNCTION(int,png_check_fp_string,(png_const_charp string, PNG_INTERNAL_FUNCTION(int,png_check_fp_string,(png_const_charp string,
png_size_t size),PNG_EMPTY); size_t size),PNG_EMPTY);
#endif /* pCAL || sCAL */ #endif /* pCAL || sCAL */
#if defined(PNG_GAMMA_SUPPORTED) ||\ #if defined(PNG_GAMMA_SUPPORTED) ||\
...@@ -1951,7 +2066,7 @@ typedef struct png_control ...@@ -1951,7 +2066,7 @@ typedef struct png_control
png_voidp error_buf; /* Always a jmp_buf at present. */ png_voidp error_buf; /* Always a jmp_buf at present. */
png_const_bytep memory; /* Memory buffer. */ png_const_bytep memory; /* Memory buffer. */
png_size_t size; /* Size of the memory buffer. */ size_t size; /* Size of the memory buffer. */
unsigned int for_write :1; /* Otherwise it is a read structure */ unsigned int for_write :1; /* Otherwise it is a read structure */
unsigned int owned_file :1; /* We own the file in io_ptr */ unsigned int owned_file :1; /* We own the file in io_ptr */
...@@ -2019,6 +2134,11 @@ PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_neon, ...@@ -2019,6 +2134,11 @@ PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_neon,
PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_msa, PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_msa,
(png_structp png_ptr, unsigned int bpp), PNG_EMPTY); (png_structp png_ptr, unsigned int bpp), PNG_EMPTY);
#endif #endif
# if PNG_INTEL_SSE_IMPLEMENTATION > 0
PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_sse2,
(png_structp png_ptr, unsigned int bpp), PNG_EMPTY);
# endif
#endif #endif
PNG_INTERNAL_FUNCTION(png_uint_32, png_check_keyword, (png_structrp png_ptr, PNG_INTERNAL_FUNCTION(png_uint_32, png_check_keyword, (png_structrp png_ptr,
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
* However, the following notice accompanied the original version of this * However, the following notice accompanied the original version of this
* file and, per its terms, should not be removed: * file and, per its terms, should not be removed:
* *
* Last changed in libpng 1.6.26 [October 20, 2016] * Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
...@@ -203,6 +203,11 @@ png_read_info(png_structrp png_ptr, png_inforp info_ptr) ...@@ -203,6 +203,11 @@ png_read_info(png_structrp png_ptr, png_inforp info_ptr)
png_handle_cHRM(png_ptr, info_ptr, length); png_handle_cHRM(png_ptr, info_ptr, length);
#endif #endif
#ifdef PNG_READ_eXIf_SUPPORTED
else if (chunk_name == png_eXIf)
png_handle_eXIf(png_ptr, info_ptr, length);
#endif
#ifdef PNG_READ_gAMA_SUPPORTED #ifdef PNG_READ_gAMA_SUPPORTED
else if (chunk_name == png_gAMA) else if (chunk_name == png_gAMA)
png_handle_gAMA(png_ptr, info_ptr, length); png_handle_gAMA(png_ptr, info_ptr, length);
...@@ -562,6 +567,7 @@ png_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row) ...@@ -562,6 +567,7 @@ png_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row)
png_error(png_ptr, "Invalid attempt to read row data"); png_error(png_ptr, "Invalid attempt to read row data");
/* Fill the row with IDAT data: */ /* Fill the row with IDAT data: */
png_ptr->row_buf[0]=255; /* to force error if no data was found */
png_read_IDAT_data(png_ptr, png_ptr->row_buf, row_info.rowbytes + 1); png_read_IDAT_data(png_ptr, png_ptr->row_buf, row_info.rowbytes + 1);
if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE) if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE)
...@@ -870,6 +876,11 @@ png_read_end(png_structrp png_ptr, png_inforp info_ptr) ...@@ -870,6 +876,11 @@ png_read_end(png_structrp png_ptr, png_inforp info_ptr)
png_handle_cHRM(png_ptr, info_ptr, length); png_handle_cHRM(png_ptr, info_ptr, length);
#endif #endif
#ifdef PNG_READ_eXIf_SUPPORTED
else if (chunk_name == png_eXIf)
png_handle_eXIf(png_ptr, info_ptr, length);
#endif
#ifdef PNG_READ_gAMA_SUPPORTED #ifdef PNG_READ_gAMA_SUPPORTED
else if (chunk_name == png_gAMA) else if (chunk_name == png_gAMA)
png_handle_gAMA(png_ptr, info_ptr, length); png_handle_gAMA(png_ptr, info_ptr, length);
...@@ -1549,7 +1560,7 @@ png_image_begin_read_from_file(png_imagep image, const char *file_name) ...@@ -1549,7 +1560,7 @@ png_image_begin_read_from_file(png_imagep image, const char *file_name)
#endif /* STDIO */ #endif /* STDIO */
static void PNGCBAPI static void PNGCBAPI
png_image_memory_read(png_structp png_ptr, png_bytep out, png_size_t need) png_image_memory_read(png_structp png_ptr, png_bytep out, size_t need)
{ {
if (png_ptr != NULL) if (png_ptr != NULL)
{ {
...@@ -1560,7 +1571,7 @@ png_image_memory_read(png_structp png_ptr, png_bytep out, png_size_t need) ...@@ -1560,7 +1571,7 @@ png_image_memory_read(png_structp png_ptr, png_bytep out, png_size_t need)
if (cp != NULL) if (cp != NULL)
{ {
png_const_bytep memory = cp->memory; png_const_bytep memory = cp->memory;
png_size_t size = cp->size; size_t size = cp->size;
if (memory != NULL && size >= need) if (memory != NULL && size >= need)
{ {
...@@ -1579,7 +1590,7 @@ png_image_memory_read(png_structp png_ptr, png_bytep out, png_size_t need) ...@@ -1579,7 +1590,7 @@ png_image_memory_read(png_structp png_ptr, png_bytep out, png_size_t need)
} }
int PNGAPI png_image_begin_read_from_memory(png_imagep image, int PNGAPI png_image_begin_read_from_memory(png_imagep image,
png_const_voidp memory, png_size_t size) png_const_voidp memory, size_t size)
{ {
if (image != NULL && image->version == PNG_IMAGE_VERSION) if (image != NULL && image->version == PNG_IMAGE_VERSION)
{ {
...@@ -1911,7 +1922,7 @@ png_create_colormap_entry(png_image_read_control *display, ...@@ -1911,7 +1922,7 @@ png_create_colormap_entry(png_image_read_control *display,
{ {
case 4: case 4:
entry[afirst ? 0 : 3] = (png_uint_16)alpha; entry[afirst ? 0 : 3] = (png_uint_16)alpha;
/* FALL THROUGH */ /* FALLTHROUGH */
case 3: case 3:
if (alpha < 65535) if (alpha < 65535)
...@@ -1933,7 +1944,7 @@ png_create_colormap_entry(png_image_read_control *display, ...@@ -1933,7 +1944,7 @@ png_create_colormap_entry(png_image_read_control *display,
case 2: case 2:
entry[1 ^ afirst] = (png_uint_16)alpha; entry[1 ^ afirst] = (png_uint_16)alpha;
/* FALL THROUGH */ /* FALLTHROUGH */
case 1: case 1:
if (alpha < 65535) if (alpha < 65535)
...@@ -1962,6 +1973,7 @@ png_create_colormap_entry(png_image_read_control *display, ...@@ -1962,6 +1973,7 @@ png_create_colormap_entry(png_image_read_control *display,
{ {
case 4: case 4:
entry[afirst ? 0 : 3] = (png_byte)alpha; entry[afirst ? 0 : 3] = (png_byte)alpha;
/* FALLTHROUGH */
case 3: case 3:
entry[afirst + (2 ^ bgr)] = (png_byte)blue; entry[afirst + (2 ^ bgr)] = (png_byte)blue;
entry[afirst + 1] = (png_byte)green; entry[afirst + 1] = (png_byte)green;
...@@ -1970,6 +1982,7 @@ png_create_colormap_entry(png_image_read_control *display, ...@@ -1970,6 +1982,7 @@ png_create_colormap_entry(png_image_read_control *display,
case 2: case 2:
entry[1 ^ afirst] = (png_byte)alpha; entry[1 ^ afirst] = (png_byte)alpha;
/* FALLTHROUGH */
case 1: case 1:
entry[afirst] = (png_byte)green; entry[afirst] = (png_byte)green;
break; break;
...@@ -2889,7 +2902,7 @@ png_image_read_colormap(png_voidp argument) ...@@ -2889,7 +2902,7 @@ png_image_read_colormap(png_voidp argument)
case P_sRGB: case P_sRGB:
/* Change to 8-bit sRGB */ /* Change to 8-bit sRGB */
png_set_alpha_mode_fixed(png_ptr, PNG_ALPHA_PNG, PNG_GAMMA_sRGB); png_set_alpha_mode_fixed(png_ptr, PNG_ALPHA_PNG, PNG_GAMMA_sRGB);
/* FALL THROUGH */ /* FALLTHROUGH */
case P_FILE: case P_FILE:
if (png_ptr->bit_depth > 8) if (png_ptr->bit_depth > 8)
...@@ -3207,8 +3220,7 @@ png_image_read_colormapped(png_voidp argument) ...@@ -3207,8 +3220,7 @@ png_image_read_colormapped(png_voidp argument)
image->colormap_entries == 244 /* 216 + 1 + 27 */) image->colormap_entries == 244 /* 216 + 1 + 27 */)
break; break;
/* goto bad_output; */ goto bad_output;
/* FALL THROUGH */
default: default:
bad_output: bad_output:
...@@ -3776,6 +3788,12 @@ png_image_read_direct(png_voidp argument) ...@@ -3776,6 +3788,12 @@ png_image_read_direct(png_voidp argument)
output_gamma = PNG_DEFAULT_sRGB; output_gamma = PNG_DEFAULT_sRGB;
} }
if ((change & PNG_FORMAT_FLAG_ASSOCIATED_ALPHA) != 0)
{
mode = PNG_ALPHA_OPTIMIZED;
change &= ~PNG_FORMAT_FLAG_ASSOCIATED_ALPHA;
}
/* If 'do_local_background' is set check for the presence of gamma /* If 'do_local_background' is set check for the presence of gamma
* correction; this is part of the work-round for the libpng bug * correction; this is part of the work-round for the libpng bug
* described above. * described above.
...@@ -4001,6 +4019,10 @@ png_image_read_direct(png_voidp argument) ...@@ -4001,6 +4019,10 @@ png_image_read_direct(png_voidp argument)
else if (do_local_compose != 0) /* internal error */ else if (do_local_compose != 0) /* internal error */
png_error(png_ptr, "png_image_read: alpha channel lost"); png_error(png_ptr, "png_image_read: alpha channel lost");
if ((format & PNG_FORMAT_FLAG_ASSOCIATED_ALPHA) != 0) {
info_format |= PNG_FORMAT_FLAG_ASSOCIATED_ALPHA;
}
if (info_ptr->bit_depth == 16) if (info_ptr->bit_depth == 16)
info_format |= PNG_FORMAT_FLAG_LINEAR; info_format |= PNG_FORMAT_FLAG_LINEAR;
...@@ -4156,7 +4178,7 @@ png_image_finish_read(png_imagep image, png_const_colorp background, ...@@ -4156,7 +4178,7 @@ png_image_finish_read(png_imagep image, png_const_colorp background,
* *
* NOTE: this will be changed in 1.7 because PNG_IMAGE_BUFFER_SIZE * NOTE: this will be changed in 1.7 because PNG_IMAGE_BUFFER_SIZE
* will be changed to use png_alloc_size_t; bigger images can be * will be changed to use png_alloc_size_t; bigger images can be
* accomodated on 64-bit systems. * accommodated on 64-bit systems.
*/ */
if (image->height <= if (image->height <=
0xffffffffU/PNG_IMAGE_PIXEL_COMPONENT_SIZE(image->format)/check) 0xffffffffU/PNG_IMAGE_PIXEL_COMPONENT_SIZE(image->format)/check)
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
* However, the following notice accompanied the original version of this * However, the following notice accompanied the original version of this
* file and, per its terms, should not be removed: * file and, per its terms, should not be removed:
* *
* Last changed in libpng 1.6.24 [August 4, 2016] * Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2016,2018 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
* to read more than 64K on a 16-bit machine. * to read more than 64K on a 16-bit machine.
*/ */
void /* PRIVATE */ void /* PRIVATE */
png_read_data(png_structrp png_ptr, png_bytep data, png_size_t length) png_read_data(png_structrp png_ptr, png_bytep data, size_t length)
{ {
png_debug1(4, "reading %d bytes", (int)length); png_debug1(4, "reading %d bytes", (int)length);
...@@ -75,14 +75,14 @@ png_read_data(png_structrp png_ptr, png_bytep data, png_size_t length) ...@@ -75,14 +75,14 @@ png_read_data(png_structrp png_ptr, png_bytep data, png_size_t length)
* than changing the library. * than changing the library.
*/ */
void PNGCBAPI void PNGCBAPI
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) png_default_read_data(png_structp png_ptr, png_bytep data, size_t length)
{ {
png_size_t check; size_t check;
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
/* fread() returns 0 on error, so it is OK to store this in a png_size_t /* fread() returns 0 on error, so it is OK to store this in a size_t
* instead of an int, which is what fread() actually returns. * instead of an int, which is what fread() actually returns.
*/ */
check = fread(data, 1, length, png_voidcast(png_FILE_p, png_ptr->io_ptr)); check = fread(data, 1, length, png_voidcast(png_FILE_p, png_ptr->io_ptr));
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
* However, the following notice accompanied the original version of this * However, the following notice accompanied the original version of this
* file and, per its terms, should not be removed: * file and, per its terms, should not be removed:
* *
* Last changed in libpng 1.6.24 [August 4, 2016] * Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
...@@ -77,6 +77,7 @@ png_set_crc_action(png_structrp png_ptr, int crit_action, int ancil_action) ...@@ -77,6 +77,7 @@ png_set_crc_action(png_structrp png_ptr, int crit_action, int ancil_action)
case PNG_CRC_WARN_DISCARD: /* Not a valid action for critical data */ case PNG_CRC_WARN_DISCARD: /* Not a valid action for critical data */
png_warning(png_ptr, png_warning(png_ptr,
"Can't discard critical data on CRC error"); "Can't discard critical data on CRC error");
/* FALLTHROUGH */
case PNG_CRC_ERROR_QUIT: /* Error/quit */ case PNG_CRC_ERROR_QUIT: /* Error/quit */
case PNG_CRC_DEFAULT: case PNG_CRC_DEFAULT:
...@@ -319,7 +320,7 @@ png_set_alpha_mode_fixed(png_structrp png_ptr, int mode, ...@@ -319,7 +320,7 @@ png_set_alpha_mode_fixed(png_structrp png_ptr, int mode,
* who use the inverse of the gamma value accidentally! Since some of these * who use the inverse of the gamma value accidentally! Since some of these
* values are reasonable this may have to be changed: * values are reasonable this may have to be changed:
* *
* 1.6.x: changed from 0.07..3 to 0.01..100 (to accomodate the optimal 16-bit * 1.6.x: changed from 0.07..3 to 0.01..100 (to accommodate the optimal 16-bit
* gamma of 36, and its reciprocal.) * gamma of 36, and its reciprocal.)
*/ */
if (output_gamma < 1000 || output_gamma > 10000000) if (output_gamma < 1000 || output_gamma > 10000000)
...@@ -457,7 +458,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette, ...@@ -457,7 +458,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
int i; int i;
png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr, png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr,
(png_uint_32)((png_uint_32)num_palette * (sizeof (png_byte)))); (png_alloc_size_t)((png_uint_32)num_palette * (sizeof (png_byte))));
for (i = 0; i < num_palette; i++) for (i = 0; i < num_palette; i++)
png_ptr->quantize_index[i] = (png_byte)i; png_ptr->quantize_index[i] = (png_byte)i;
} }
...@@ -474,7 +475,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette, ...@@ -474,7 +475,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
/* Initialize an array to sort colors */ /* Initialize an array to sort colors */
png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr, png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr,
(png_uint_32)((png_uint_32)num_palette * (sizeof (png_byte)))); (png_alloc_size_t)((png_uint_32)num_palette * (sizeof (png_byte))));
/* Initialize the quantize_sort array */ /* Initialize the quantize_sort array */
for (i = 0; i < num_palette; i++) for (i = 0; i < num_palette; i++)
...@@ -608,9 +609,11 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette, ...@@ -608,9 +609,11 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
/* Initialize palette index arrays */ /* Initialize palette index arrays */
png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr, png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
(png_uint_32)((png_uint_32)num_palette * (sizeof (png_byte)))); (png_alloc_size_t)((png_uint_32)num_palette *
(sizeof (png_byte))));
png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr, png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
(png_uint_32)((png_uint_32)num_palette * (sizeof (png_byte)))); (png_alloc_size_t)((png_uint_32)num_palette *
(sizeof (png_byte))));
/* Initialize the sort array */ /* Initialize the sort array */
for (i = 0; i < num_palette; i++) for (i = 0; i < num_palette; i++)
...@@ -619,7 +622,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette, ...@@ -619,7 +622,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
png_ptr->palette_to_index[i] = (png_byte)i; png_ptr->palette_to_index[i] = (png_byte)i;
} }
hash = (png_dsortpp)png_calloc(png_ptr, (png_uint_32)(769 * hash = (png_dsortpp)png_calloc(png_ptr, (png_alloc_size_t)(769 *
(sizeof (png_dsortp)))); (sizeof (png_dsortp))));
num_new_palette = num_palette; num_new_palette = num_palette;
...@@ -650,7 +653,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette, ...@@ -650,7 +653,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
{ {
t = (png_dsortp)png_malloc_warn(png_ptr, t = (png_dsortp)png_malloc_warn(png_ptr,
(png_uint_32)(sizeof (png_dsort))); (png_alloc_size_t)(sizeof (png_dsort)));
if (t == NULL) if (t == NULL)
break; break;
...@@ -772,12 +775,12 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette, ...@@ -772,12 +775,12 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
int num_red = (1 << PNG_QUANTIZE_RED_BITS); int num_red = (1 << PNG_QUANTIZE_RED_BITS);
int num_green = (1 << PNG_QUANTIZE_GREEN_BITS); int num_green = (1 << PNG_QUANTIZE_GREEN_BITS);
int num_blue = (1 << PNG_QUANTIZE_BLUE_BITS); int num_blue = (1 << PNG_QUANTIZE_BLUE_BITS);
png_size_t num_entries = ((png_size_t)1 << total_bits); size_t num_entries = ((size_t)1 << total_bits);
png_ptr->palette_lookup = (png_bytep)png_calloc(png_ptr, png_ptr->palette_lookup = (png_bytep)png_calloc(png_ptr,
(png_uint_32)(num_entries * (sizeof (png_byte)))); (png_alloc_size_t)(num_entries * (sizeof (png_byte))));
distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries * distance = (png_bytep)png_malloc(png_ptr, (png_alloc_size_t)(num_entries *
(sizeof (png_byte)))); (sizeof (png_byte))));
memset(distance, 0xff, num_entries * (sizeof (png_byte))); memset(distance, 0xff, num_entries * (sizeof (png_byte)));
...@@ -1281,7 +1284,7 @@ png_init_rgb_transformations(png_structrp png_ptr) ...@@ -1281,7 +1284,7 @@ png_init_rgb_transformations(png_structrp png_ptr)
default: default:
case 8: case 8:
/* FALL THROUGH (Already 8 bits) */ /* FALLTHROUGH */ /* (Already 8 bits) */
case 16: case 16:
/* Already a full 16 bits */ /* Already a full 16 bits */
...@@ -1342,7 +1345,7 @@ png_init_read_transformations(png_structrp png_ptr) ...@@ -1342,7 +1345,7 @@ png_init_read_transformations(png_structrp png_ptr)
else if (png_ptr->screen_gamma != 0) else if (png_ptr->screen_gamma != 0)
/* The converse - assume the file matches the screen, note that this /* The converse - assume the file matches the screen, note that this
* perhaps undesireable default can (from 1.5.4) be changed by calling * perhaps undesirable default can (from 1.5.4) be changed by calling
* png_set_alpha_mode (even if the alpha handling mode isn't required * png_set_alpha_mode (even if the alpha handling mode isn't required
* or isn't changed from the default.) * or isn't changed from the default.)
*/ */
...@@ -1910,7 +1913,7 @@ png_init_read_transformations(png_structrp png_ptr) ...@@ -1910,7 +1913,7 @@ png_init_read_transformations(png_structrp png_ptr)
png_ptr->transformations &= ~PNG_SHIFT; png_ptr->transformations &= ~PNG_SHIFT;
/* significant bits can be in the range 1 to 7 for a meaninful result, if /* significant bits can be in the range 1 to 7 for a meaningful result, if
* the number of significant bits is 0 then no shift is done (this is an * the number of significant bits is 0 then no shift is done (this is an
* error condition which is silently ignored.) * error condition which is silently ignored.)
*/ */
...@@ -2176,8 +2179,8 @@ png_do_unpack(png_row_infop row_info, png_bytep row) ...@@ -2176,8 +2179,8 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
{ {
case 1: case 1:
{ {
png_bytep sp = row + (png_size_t)((row_width - 1) >> 3); png_bytep sp = row + (size_t)((row_width - 1) >> 3);
png_bytep dp = row + (png_size_t)row_width - 1; png_bytep dp = row + (size_t)row_width - 1;
png_uint_32 shift = 7U - ((row_width + 7U) & 0x07); png_uint_32 shift = 7U - ((row_width + 7U) & 0x07);
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
...@@ -2200,8 +2203,8 @@ png_do_unpack(png_row_infop row_info, png_bytep row) ...@@ -2200,8 +2203,8 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
case 2: case 2:
{ {
png_bytep sp = row + (png_size_t)((row_width - 1) >> 2); png_bytep sp = row + (size_t)((row_width - 1) >> 2);
png_bytep dp = row + (png_size_t)row_width - 1; png_bytep dp = row + (size_t)row_width - 1;
png_uint_32 shift = ((3U - ((row_width + 3U) & 0x03)) << 1); png_uint_32 shift = ((3U - ((row_width + 3U) & 0x03)) << 1);
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
...@@ -2223,8 +2226,8 @@ png_do_unpack(png_row_infop row_info, png_bytep row) ...@@ -2223,8 +2226,8 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
case 4: case 4:
{ {
png_bytep sp = row + (png_size_t)((row_width - 1) >> 1); png_bytep sp = row + (size_t)((row_width - 1) >> 1);
png_bytep dp = row + (png_size_t)row_width - 1; png_bytep dp = row + (size_t)row_width - 1;
png_uint_32 shift = ((1U - ((row_width + 1U) & 0x01)) << 2); png_uint_32 shift = ((1U - ((row_width + 1U) & 0x01)) << 2);
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
...@@ -2488,95 +2491,94 @@ png_do_chop(png_row_infop row_info, png_bytep row) ...@@ -2488,95 +2491,94 @@ png_do_chop(png_row_infop row_info, png_bytep row)
static void static void
png_do_read_swap_alpha(png_row_infop row_info, png_bytep row) png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
{ {
png_uint_32 row_width = row_info->width;
png_debug(1, "in png_do_read_swap_alpha"); png_debug(1, "in png_do_read_swap_alpha");
if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
{ {
png_uint_32 row_width = row_info->width; /* This converts from RGBA to ARGB */
if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) if (row_info->bit_depth == 8)
{ {
/* This converts from RGBA to ARGB */ png_bytep sp = row + row_info->rowbytes;
if (row_info->bit_depth == 8) png_bytep dp = sp;
{ png_byte save;
png_bytep sp = row + row_info->rowbytes; png_uint_32 i;
png_bytep dp = sp;
png_byte save;
png_uint_32 i;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
save = *(--sp); save = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = save; *(--dp) = save;
}
} }
}
#ifdef PNG_READ_16BIT_SUPPORTED #ifdef PNG_READ_16BIT_SUPPORTED
/* This converts from RRGGBBAA to AARRGGBB */ /* This converts from RRGGBBAA to AARRGGBB */
else else
{ {
png_bytep sp = row + row_info->rowbytes; png_bytep sp = row + row_info->rowbytes;
png_bytep dp = sp; png_bytep dp = sp;
png_byte save[2]; png_byte save[2];
png_uint_32 i; png_uint_32 i;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
save[0] = *(--sp); save[0] = *(--sp);
save[1] = *(--sp); save[1] = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = save[0]; *(--dp) = save[0];
*(--dp) = save[1]; *(--dp) = save[1];
}
} }
#endif
} }
#endif
}
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
{
/* This converts from GA to AG */
if (row_info->bit_depth == 8)
{ {
/* This converts from GA to AG */ png_bytep sp = row + row_info->rowbytes;
if (row_info->bit_depth == 8) png_bytep dp = sp;
{ png_byte save;
png_bytep sp = row + row_info->rowbytes; png_uint_32 i;
png_bytep dp = sp;
png_byte save;
png_uint_32 i;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
save = *(--sp); save = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = save; *(--dp) = save;
}
} }
}
#ifdef PNG_READ_16BIT_SUPPORTED #ifdef PNG_READ_16BIT_SUPPORTED
/* This converts from GGAA to AAGG */ /* This converts from GGAA to AAGG */
else else
{ {
png_bytep sp = row + row_info->rowbytes; png_bytep sp = row + row_info->rowbytes;
png_bytep dp = sp; png_bytep dp = sp;
png_byte save[2]; png_byte save[2];
png_uint_32 i; png_uint_32 i;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
save[0] = *(--sp); save[0] = *(--sp);
save[1] = *(--sp); save[1] = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = save[0]; *(--dp) = save[0];
*(--dp) = save[1]; *(--dp) = save[1];
}
} }
#endif
} }
#endif
} }
} }
#endif #endif
...@@ -2706,8 +2708,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row, ...@@ -2706,8 +2708,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
if ((flags & PNG_FLAG_FILLER_AFTER) != 0) if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
{ {
/* This changes the data from G to GX */ /* This changes the data from G to GX */
png_bytep sp = row + (png_size_t)row_width; png_bytep sp = row + (size_t)row_width;
png_bytep dp = sp + (png_size_t)row_width; png_bytep dp = sp + (size_t)row_width;
for (i = 1; i < row_width; i++) for (i = 1; i < row_width; i++)
{ {
*(--dp) = lo_filler; *(--dp) = lo_filler;
...@@ -2722,8 +2724,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row, ...@@ -2722,8 +2724,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
else else
{ {
/* This changes the data from G to XG */ /* This changes the data from G to XG */
png_bytep sp = row + (png_size_t)row_width; png_bytep sp = row + (size_t)row_width;
png_bytep dp = sp + (png_size_t)row_width; png_bytep dp = sp + (size_t)row_width;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(--dp) = *(--sp); *(--dp) = *(--sp);
...@@ -2741,8 +2743,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row, ...@@ -2741,8 +2743,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
if ((flags & PNG_FLAG_FILLER_AFTER) != 0) if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
{ {
/* This changes the data from GG to GGXX */ /* This changes the data from GG to GGXX */
png_bytep sp = row + (png_size_t)row_width * 2; png_bytep sp = row + (size_t)row_width * 2;
png_bytep dp = sp + (png_size_t)row_width * 2; png_bytep dp = sp + (size_t)row_width * 2;
for (i = 1; i < row_width; i++) for (i = 1; i < row_width; i++)
{ {
*(--dp) = lo_filler; *(--dp) = lo_filler;
...@@ -2760,8 +2762,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row, ...@@ -2760,8 +2762,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
else else
{ {
/* This changes the data from GG to XXGG */ /* This changes the data from GG to XXGG */
png_bytep sp = row + (png_size_t)row_width * 2; png_bytep sp = row + (size_t)row_width * 2;
png_bytep dp = sp + (png_size_t)row_width * 2; png_bytep dp = sp + (size_t)row_width * 2;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(--dp) = *(--sp); *(--dp) = *(--sp);
...@@ -2783,8 +2785,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row, ...@@ -2783,8 +2785,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
if ((flags & PNG_FLAG_FILLER_AFTER) != 0) if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
{ {
/* This changes the data from RGB to RGBX */ /* This changes the data from RGB to RGBX */
png_bytep sp = row + (png_size_t)row_width * 3; png_bytep sp = row + (size_t)row_width * 3;
png_bytep dp = sp + (png_size_t)row_width; png_bytep dp = sp + (size_t)row_width;
for (i = 1; i < row_width; i++) for (i = 1; i < row_width; i++)
{ {
*(--dp) = lo_filler; *(--dp) = lo_filler;
...@@ -2801,8 +2803,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row, ...@@ -2801,8 +2803,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
else else
{ {
/* This changes the data from RGB to XRGB */ /* This changes the data from RGB to XRGB */
png_bytep sp = row + (png_size_t)row_width * 3; png_bytep sp = row + (size_t)row_width * 3;
png_bytep dp = sp + (png_size_t)row_width; png_bytep dp = sp + (size_t)row_width;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(--dp) = *(--sp); *(--dp) = *(--sp);
...@@ -2822,8 +2824,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row, ...@@ -2822,8 +2824,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
if ((flags & PNG_FLAG_FILLER_AFTER) != 0) if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
{ {
/* This changes the data from RRGGBB to RRGGBBXX */ /* This changes the data from RRGGBB to RRGGBBXX */
png_bytep sp = row + (png_size_t)row_width * 6; png_bytep sp = row + (size_t)row_width * 6;
png_bytep dp = sp + (png_size_t)row_width * 2; png_bytep dp = sp + (size_t)row_width * 2;
for (i = 1; i < row_width; i++) for (i = 1; i < row_width; i++)
{ {
*(--dp) = lo_filler; *(--dp) = lo_filler;
...@@ -2845,8 +2847,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row, ...@@ -2845,8 +2847,8 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
else else
{ {
/* This changes the data from RRGGBB to XXRRGGBB */ /* This changes the data from RRGGBB to XXRRGGBB */
png_bytep sp = row + (png_size_t)row_width * 6; png_bytep sp = row + (size_t)row_width * 6;
png_bytep dp = sp + (png_size_t)row_width * 2; png_bytep dp = sp + (size_t)row_width * 2;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(--dp) = *(--sp); *(--dp) = *(--sp);
...@@ -2887,8 +2889,8 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) ...@@ -2887,8 +2889,8 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
if (row_info->bit_depth == 8) if (row_info->bit_depth == 8)
{ {
/* This changes G to RGB */ /* This changes G to RGB */
png_bytep sp = row + (png_size_t)row_width - 1; png_bytep sp = row + (size_t)row_width - 1;
png_bytep dp = sp + (png_size_t)row_width * 2; png_bytep dp = sp + (size_t)row_width * 2;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(dp--) = *sp; *(dp--) = *sp;
...@@ -2900,8 +2902,8 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) ...@@ -2900,8 +2902,8 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
else else
{ {
/* This changes GG to RRGGBB */ /* This changes GG to RRGGBB */
png_bytep sp = row + (png_size_t)row_width * 2 - 1; png_bytep sp = row + (size_t)row_width * 2 - 1;
png_bytep dp = sp + (png_size_t)row_width * 4; png_bytep dp = sp + (size_t)row_width * 4;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(dp--) = *sp; *(dp--) = *sp;
...@@ -2919,8 +2921,8 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) ...@@ -2919,8 +2921,8 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
if (row_info->bit_depth == 8) if (row_info->bit_depth == 8)
{ {
/* This changes GA to RGBA */ /* This changes GA to RGBA */
png_bytep sp = row + (png_size_t)row_width * 2 - 1; png_bytep sp = row + (size_t)row_width * 2 - 1;
png_bytep dp = sp + (png_size_t)row_width * 2; png_bytep dp = sp + (size_t)row_width * 2;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(dp--) = *(sp--); *(dp--) = *(sp--);
...@@ -2933,8 +2935,8 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) ...@@ -2933,8 +2935,8 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
else else
{ {
/* This changes GGAA to RRGGBBAA */ /* This changes GGAA to RRGGBBAA */
png_bytep sp = row + (png_size_t)row_width * 4 - 1; png_bytep sp = row + (size_t)row_width * 4 - 1;
png_bytep dp = sp + (png_size_t)row_width * 4; png_bytep dp = sp + (size_t)row_width * 4;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(dp--) = *(sp--); *(dp--) = *(sp--);
...@@ -2962,7 +2964,7 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) ...@@ -2962,7 +2964,7 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
* using the equation given in Poynton's ColorFAQ of 1998-01-04 at * using the equation given in Poynton's ColorFAQ of 1998-01-04 at
* <http://www.inforamp.net/~poynton/> (THIS LINK IS DEAD June 2008 but * <http://www.inforamp.net/~poynton/> (THIS LINK IS DEAD June 2008 but
* versions dated 1998 through November 2002 have been archived at * versions dated 1998 through November 2002 have been archived at
* http://web.archive.org/web/20000816232553/http://www.inforamp.net/ * https://web.archive.org/web/20000816232553/www.inforamp.net/
* ~poynton/notes/colour_and_gamma/ColorFAQ.txt ) * ~poynton/notes/colour_and_gamma/ColorFAQ.txt )
* Charles Poynton poynton at poynton.com * Charles Poynton poynton at poynton.com
* *
...@@ -3005,7 +3007,7 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) ...@@ -3005,7 +3007,7 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
* values this results in an implicit assumption that the original PNG RGB * values this results in an implicit assumption that the original PNG RGB
* values were linear. * values were linear.
* *
* Other integer coefficents can be used via png_set_rgb_to_gray(). Because * Other integer coefficients can be used via png_set_rgb_to_gray(). Because
* the API takes just red and green coefficients the blue coefficient is * the API takes just red and green coefficients the blue coefficient is
* calculated to make the sum 32768. This will result in different rounding * calculated to make the sum 32768. This will result in different rounding
* to that used above. * to that used above.
...@@ -3234,720 +3236,718 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr) ...@@ -3234,720 +3236,718 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
png_debug(1, "in png_do_compose"); png_debug(1, "in png_do_compose");
switch (row_info->color_type)
{ {
switch (row_info->color_type) case PNG_COLOR_TYPE_GRAY:
{ {
case PNG_COLOR_TYPE_GRAY: switch (row_info->bit_depth)
{ {
switch (row_info->bit_depth) case 1:
{
sp = row;
shift = 7;
for (i = 0; i < row_width; i++)
{
if ((png_uint_16)((*sp >> shift) & 0x01)
== png_ptr->trans_color.gray)
{
unsigned int tmp = *sp & (0x7f7f >> (7 - shift));
tmp |=
(unsigned int)(png_ptr->background.gray << shift);
*sp = (png_byte)(tmp & 0xff);
}
if (shift == 0)
{
shift = 7;
sp++;
}
else
shift--;
}
break;
}
case 2:
{ {
case 1: #ifdef PNG_READ_GAMMA_SUPPORTED
if (gamma_table != NULL)
{ {
sp = row; sp = row;
shift = 7; shift = 6;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
if ((png_uint_16)((*sp >> shift) & 0x01) if ((png_uint_16)((*sp >> shift) & 0x03)
== png_ptr->trans_color.gray) == png_ptr->trans_color.gray)
{ {
unsigned int tmp = *sp & (0x7f7f >> (7 - shift)); unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
tmp |= tmp |=
(unsigned int)(png_ptr->background.gray << shift); (unsigned int)png_ptr->background.gray << shift;
*sp = (png_byte)(tmp & 0xff);
}
else
{
unsigned int p = (*sp >> shift) & 0x03;
unsigned int g = (gamma_table [p | (p << 2) |
(p << 4) | (p << 6)] >> 6) & 0x03;
unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
tmp |= (unsigned int)(g << shift);
*sp = (png_byte)(tmp & 0xff); *sp = (png_byte)(tmp & 0xff);
} }
if (shift == 0) if (shift == 0)
{ {
shift = 7; shift = 6;
sp++; sp++;
} }
else else
shift--; shift -= 2;
} }
break;
} }
case 2: else
#endif
{ {
#ifdef PNG_READ_GAMMA_SUPPORTED sp = row;
if (gamma_table != NULL) shift = 6;
for (i = 0; i < row_width; i++)
{ {
sp = row; if ((png_uint_16)((*sp >> shift) & 0x03)
shift = 6; == png_ptr->trans_color.gray)
for (i = 0; i < row_width; i++)
{ {
if ((png_uint_16)((*sp >> shift) & 0x03) unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
== png_ptr->trans_color.gray) tmp |=
{ (unsigned int)png_ptr->background.gray << shift;
unsigned int tmp = *sp & (0x3f3f >> (6 - shift)); *sp = (png_byte)(tmp & 0xff);
tmp |=
(unsigned int)png_ptr->background.gray << shift;
*sp = (png_byte)(tmp & 0xff);
}
else
{
unsigned int p = (*sp >> shift) & 0x03;
unsigned int g = (gamma_table [p | (p << 2) |
(p << 4) | (p << 6)] >> 6) & 0x03;
unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
tmp |= (unsigned int)(g << shift);
*sp = (png_byte)(tmp & 0xff);
}
if (shift == 0)
{
shift = 6;
sp++;
}
else
shift -= 2;
} }
}
else if (shift == 0)
#endif
{
sp = row;
shift = 6;
for (i = 0; i < row_width; i++)
{ {
if ((png_uint_16)((*sp >> shift) & 0x03) shift = 6;
== png_ptr->trans_color.gray) sp++;
{
unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
tmp |=
(unsigned int)png_ptr->background.gray << shift;
*sp = (png_byte)(tmp & 0xff);
}
if (shift == 0)
{
shift = 6;
sp++;
}
else
shift -= 2;
} }
else
shift -= 2;
} }
break;
} }
break;
}
case 4: case 4:
{ {
#ifdef PNG_READ_GAMMA_SUPPORTED #ifdef PNG_READ_GAMMA_SUPPORTED
if (gamma_table != NULL) if (gamma_table != NULL)
{
sp = row;
shift = 4;
for (i = 0; i < row_width; i++)
{ {
sp = row; if ((png_uint_16)((*sp >> shift) & 0x0f)
shift = 4; == png_ptr->trans_color.gray)
for (i = 0; i < row_width; i++)
{ {
if ((png_uint_16)((*sp >> shift) & 0x0f) unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
== png_ptr->trans_color.gray) tmp |=
{ (unsigned int)(png_ptr->background.gray << shift);
unsigned int tmp = *sp & (0x0f0f >> (4 - shift)); *sp = (png_byte)(tmp & 0xff);
tmp |=
(unsigned int)(png_ptr->background.gray << shift);
*sp = (png_byte)(tmp & 0xff);
}
else
{
unsigned int p = (*sp >> shift) & 0x0f;
unsigned int g = (gamma_table[p | (p << 4)] >> 4) &
0x0f;
unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
tmp |= (unsigned int)(g << shift);
*sp = (png_byte)(tmp & 0xff);
}
if (shift == 0)
{
shift = 4;
sp++;
}
else
shift -= 4;
} }
}
else else
#endif
{
sp = row;
shift = 4;
for (i = 0; i < row_width; i++)
{ {
if ((png_uint_16)((*sp >> shift) & 0x0f) unsigned int p = (*sp >> shift) & 0x0f;
== png_ptr->trans_color.gray) unsigned int g = (gamma_table[p | (p << 4)] >> 4) &
{ 0x0f;
unsigned int tmp = *sp & (0x0f0f >> (4 - shift)); unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
tmp |= tmp |= (unsigned int)(g << shift);
(unsigned int)(png_ptr->background.gray << shift); *sp = (png_byte)(tmp & 0xff);
*sp = (png_byte)(tmp & 0xff);
}
if (shift == 0)
{
shift = 4;
sp++;
}
else
shift -= 4;
} }
}
break;
}
case 8: if (shift == 0)
{
#ifdef PNG_READ_GAMMA_SUPPORTED
if (gamma_table != NULL)
{
sp = row;
for (i = 0; i < row_width; i++, sp++)
{
if (*sp == png_ptr->trans_color.gray)
*sp = (png_byte)png_ptr->background.gray;
else
*sp = gamma_table[*sp];
}
}
else
#endif
{
sp = row;
for (i = 0; i < row_width; i++, sp++)
{ {
if (*sp == png_ptr->trans_color.gray) shift = 4;
*sp = (png_byte)png_ptr->background.gray; sp++;
} }
else
shift -= 4;
} }
break;
} }
case 16: else
#endif
{ {
#ifdef PNG_READ_GAMMA_SUPPORTED sp = row;
if (gamma_16 != NULL) shift = 4;
for (i = 0; i < row_width; i++)
{ {
sp = row; if ((png_uint_16)((*sp >> shift) & 0x0f)
for (i = 0; i < row_width; i++, sp += 2) == png_ptr->trans_color.gray)
{ {
png_uint_16 v; unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
tmp |=
v = (png_uint_16)(((*sp) << 8) + *(sp + 1)); (unsigned int)(png_ptr->background.gray << shift);
*sp = (png_byte)(tmp & 0xff);
if (v == png_ptr->trans_color.gray)
{
/* Background is already in screen gamma */
*sp = (png_byte)((png_ptr->background.gray >> 8)
& 0xff);
*(sp + 1) = (png_byte)(png_ptr->background.gray
& 0xff);
}
else
{
v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
*sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff);
}
} }
}
else
#endif
{
sp = row;
for (i = 0; i < row_width; i++, sp += 2)
{
png_uint_16 v;
v = (png_uint_16)(((*sp) << 8) + *(sp + 1)); if (shift == 0)
{
if (v == png_ptr->trans_color.gray) shift = 4;
{ sp++;
*sp = (png_byte)((png_ptr->background.gray >> 8)
& 0xff);
*(sp + 1) = (png_byte)(png_ptr->background.gray
& 0xff);
}
} }
else
shift -= 4;
} }
break;
} }
break;
default:
break;
} }
break;
}
case PNG_COLOR_TYPE_RGB: case 8:
{
if (row_info->bit_depth == 8)
{ {
#ifdef PNG_READ_GAMMA_SUPPORTED #ifdef PNG_READ_GAMMA_SUPPORTED
if (gamma_table != NULL) if (gamma_table != NULL)
{ {
sp = row; sp = row;
for (i = 0; i < row_width; i++, sp += 3) for (i = 0; i < row_width; i++, sp++)
{ {
if (*sp == png_ptr->trans_color.red && if (*sp == png_ptr->trans_color.gray)
*(sp + 1) == png_ptr->trans_color.green && *sp = (png_byte)png_ptr->background.gray;
*(sp + 2) == png_ptr->trans_color.blue)
{
*sp = (png_byte)png_ptr->background.red;
*(sp + 1) = (png_byte)png_ptr->background.green;
*(sp + 2) = (png_byte)png_ptr->background.blue;
}
else else
{
*sp = gamma_table[*sp]; *sp = gamma_table[*sp];
*(sp + 1) = gamma_table[*(sp + 1)];
*(sp + 2) = gamma_table[*(sp + 2)];
}
} }
} }
else else
#endif #endif
{ {
sp = row; sp = row;
for (i = 0; i < row_width; i++, sp += 3) for (i = 0; i < row_width; i++, sp++)
{ {
if (*sp == png_ptr->trans_color.red && if (*sp == png_ptr->trans_color.gray)
*(sp + 1) == png_ptr->trans_color.green && *sp = (png_byte)png_ptr->background.gray;
*(sp + 2) == png_ptr->trans_color.blue)
{
*sp = (png_byte)png_ptr->background.red;
*(sp + 1) = (png_byte)png_ptr->background.green;
*(sp + 2) = (png_byte)png_ptr->background.blue;
}
} }
} }
break;
} }
else /* if (row_info->bit_depth == 16) */
case 16:
{ {
#ifdef PNG_READ_GAMMA_SUPPORTED #ifdef PNG_READ_GAMMA_SUPPORTED
if (gamma_16 != NULL) if (gamma_16 != NULL)
{ {
sp = row; sp = row;
for (i = 0; i < row_width; i++, sp += 6) for (i = 0; i < row_width; i++, sp += 2)
{ {
png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1)); png_uint_16 v;
png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
+ *(sp + 3));
png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8) v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
+ *(sp + 5));
if (r == png_ptr->trans_color.red && if (v == png_ptr->trans_color.gray)
g == png_ptr->trans_color.green &&
b == png_ptr->trans_color.blue)
{ {
/* Background is already in screen gamma */ /* Background is already in screen gamma */
*sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); *sp = (png_byte)((png_ptr->background.gray >> 8)
*(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); & 0xff);
*(sp + 2) = (png_byte)((png_ptr->background.green >> 8) *(sp + 1) = (png_byte)(png_ptr->background.gray
& 0xff); & 0xff);
*(sp + 3) = (png_byte)(png_ptr->background.green
& 0xff);
*(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
& 0xff);
*(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
} }
else else
{ {
png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
*sp = (png_byte)((v >> 8) & 0xff); *sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff); *(sp + 1) = (png_byte)(v & 0xff);
v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
*(sp + 2) = (png_byte)((v >> 8) & 0xff);
*(sp + 3) = (png_byte)(v & 0xff);
v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
*(sp + 4) = (png_byte)((v >> 8) & 0xff);
*(sp + 5) = (png_byte)(v & 0xff);
} }
} }
} }
else else
#endif #endif
{ {
sp = row; sp = row;
for (i = 0; i < row_width; i++, sp += 6) for (i = 0; i < row_width; i++, sp += 2)
{ {
png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1)); png_uint_16 v;
png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
+ *(sp + 3));
png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8) v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
+ *(sp + 5));
if (r == png_ptr->trans_color.red && if (v == png_ptr->trans_color.gray)
g == png_ptr->trans_color.green &&
b == png_ptr->trans_color.blue)
{ {
*sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); *sp = (png_byte)((png_ptr->background.gray >> 8)
*(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); & 0xff);
*(sp + 2) = (png_byte)((png_ptr->background.green >> 8) *(sp + 1) = (png_byte)(png_ptr->background.gray
& 0xff); & 0xff);
*(sp + 3) = (png_byte)(png_ptr->background.green
& 0xff);
*(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
& 0xff);
*(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
} }
} }
} }
break;
} }
break;
default:
break;
} }
break;
}
case PNG_COLOR_TYPE_GRAY_ALPHA: case PNG_COLOR_TYPE_RGB:
{
if (row_info->bit_depth == 8)
{ {
if (row_info->bit_depth == 8)
{
#ifdef PNG_READ_GAMMA_SUPPORTED #ifdef PNG_READ_GAMMA_SUPPORTED
if (gamma_to_1 != NULL && gamma_from_1 != NULL && if (gamma_table != NULL)
gamma_table != NULL) {
sp = row;
for (i = 0; i < row_width; i++, sp += 3)
{ {
sp = row; if (*sp == png_ptr->trans_color.red &&
for (i = 0; i < row_width; i++, sp += 2) *(sp + 1) == png_ptr->trans_color.green &&
*(sp + 2) == png_ptr->trans_color.blue)
{ {
png_uint_16 a = *(sp + 1); *sp = (png_byte)png_ptr->background.red;
*(sp + 1) = (png_byte)png_ptr->background.green;
*(sp + 2) = (png_byte)png_ptr->background.blue;
}
if (a == 0xff) else
*sp = gamma_table[*sp]; {
*sp = gamma_table[*sp];
*(sp + 1) = gamma_table[*(sp + 1)];
*(sp + 2) = gamma_table[*(sp + 2)];
}
}
}
else
#endif
{
sp = row;
for (i = 0; i < row_width; i++, sp += 3)
{
if (*sp == png_ptr->trans_color.red &&
*(sp + 1) == png_ptr->trans_color.green &&
*(sp + 2) == png_ptr->trans_color.blue)
{
*sp = (png_byte)png_ptr->background.red;
*(sp + 1) = (png_byte)png_ptr->background.green;
*(sp + 2) = (png_byte)png_ptr->background.blue;
}
}
}
}
else /* if (row_info->bit_depth == 16) */
{
#ifdef PNG_READ_GAMMA_SUPPORTED
if (gamma_16 != NULL)
{
sp = row;
for (i = 0; i < row_width; i++, sp += 6)
{
png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
else if (a == 0) png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
{ + *(sp + 3));
/* Background is already in screen gamma */
*sp = (png_byte)png_ptr->background.gray;
}
else png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
{ + *(sp + 5));
png_byte v, w;
v = gamma_to_1[*sp]; if (r == png_ptr->trans_color.red &&
png_composite(w, v, a, png_ptr->background_1.gray); g == png_ptr->trans_color.green &&
if (optimize == 0) b == png_ptr->trans_color.blue)
w = gamma_from_1[w]; {
*sp = w; /* Background is already in screen gamma */
} *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
*(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
*(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
& 0xff);
*(sp + 3) = (png_byte)(png_ptr->background.green
& 0xff);
*(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
& 0xff);
*(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
}
else
{
png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
*sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff);
v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
*(sp + 2) = (png_byte)((v >> 8) & 0xff);
*(sp + 3) = (png_byte)(v & 0xff);
v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
*(sp + 4) = (png_byte)((v >> 8) & 0xff);
*(sp + 5) = (png_byte)(v & 0xff);
} }
} }
else }
else
#endif #endif
{
sp = row;
for (i = 0; i < row_width; i++, sp += 6)
{ {
sp = row; png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
for (i = 0; i < row_width; i++, sp += 2)
png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
+ *(sp + 3));
png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
+ *(sp + 5));
if (r == png_ptr->trans_color.red &&
g == png_ptr->trans_color.green &&
b == png_ptr->trans_color.blue)
{ {
png_byte a = *(sp + 1); *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
*(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
*(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
& 0xff);
*(sp + 3) = (png_byte)(png_ptr->background.green
& 0xff);
*(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
& 0xff);
*(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
}
}
}
}
break;
}
if (a == 0) case PNG_COLOR_TYPE_GRAY_ALPHA:
*sp = (png_byte)png_ptr->background.gray; {
if (row_info->bit_depth == 8)
{
#ifdef PNG_READ_GAMMA_SUPPORTED
if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
gamma_table != NULL)
{
sp = row;
for (i = 0; i < row_width; i++, sp += 2)
{
png_uint_16 a = *(sp + 1);
if (a == 0xff)
*sp = gamma_table[*sp];
else if (a == 0)
{
/* Background is already in screen gamma */
*sp = (png_byte)png_ptr->background.gray;
}
else
{
png_byte v, w;
else if (a < 0xff) v = gamma_to_1[*sp];
png_composite(*sp, *sp, a, png_ptr->background.gray); png_composite(w, v, a, png_ptr->background_1.gray);
if (optimize == 0)
w = gamma_from_1[w];
*sp = w;
} }
} }
} }
else /* if (png_ptr->bit_depth == 16) */ else
#endif
{ {
sp = row;
for (i = 0; i < row_width; i++, sp += 2)
{
png_byte a = *(sp + 1);
if (a == 0)
*sp = (png_byte)png_ptr->background.gray;
else if (a < 0xff)
png_composite(*sp, *sp, a, png_ptr->background.gray);
}
}
}
else /* if (png_ptr->bit_depth == 16) */
{
#ifdef PNG_READ_GAMMA_SUPPORTED #ifdef PNG_READ_GAMMA_SUPPORTED
if (gamma_16 != NULL && gamma_16_from_1 != NULL && if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
gamma_16_to_1 != NULL) gamma_16_to_1 != NULL)
{
sp = row;
for (i = 0; i < row_width; i++, sp += 4)
{ {
sp = row; png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8)
for (i = 0; i < row_width; i++, sp += 4) + *(sp + 3));
{
png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8)
+ *(sp + 3));
if (a == (png_uint_16)0xffff) if (a == (png_uint_16)0xffff)
{ {
png_uint_16 v; png_uint_16 v;
v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
*sp = (png_byte)((v >> 8) & 0xff); *sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff); *(sp + 1) = (png_byte)(v & 0xff);
} }
else if (a == 0) else if (a == 0)
{ {
/* Background is already in screen gamma */ /* Background is already in screen gamma */
*sp = (png_byte)((png_ptr->background.gray >> 8) *sp = (png_byte)((png_ptr->background.gray >> 8)
& 0xff); & 0xff);
*(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff); *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
} }
else else
{ {
png_uint_16 g, v, w; png_uint_16 g, v, w;
g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp]; g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
png_composite_16(v, g, a, png_ptr->background_1.gray); png_composite_16(v, g, a, png_ptr->background_1.gray);
if (optimize != 0) if (optimize != 0)
w = v; w = v;
else else
w = gamma_16_from_1[(v & 0xff) >> w = gamma_16_from_1[(v & 0xff) >>
gamma_shift][v >> 8]; gamma_shift][v >> 8];
*sp = (png_byte)((w >> 8) & 0xff); *sp = (png_byte)((w >> 8) & 0xff);
*(sp + 1) = (png_byte)(w & 0xff); *(sp + 1) = (png_byte)(w & 0xff);
}
} }
} }
else }
else
#endif #endif
{
sp = row;
for (i = 0; i < row_width; i++, sp += 4)
{ {
sp = row; png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8)
for (i = 0; i < row_width; i++, sp += 4) + *(sp + 3));
{
png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8)
+ *(sp + 3));
if (a == 0) if (a == 0)
{ {
*sp = (png_byte)((png_ptr->background.gray >> 8) *sp = (png_byte)((png_ptr->background.gray >> 8)
& 0xff); & 0xff);
*(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff); *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
} }
else if (a < 0xffff) else if (a < 0xffff)
{ {
png_uint_16 g, v; png_uint_16 g, v;
g = (png_uint_16)(((*sp) << 8) + *(sp + 1)); g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
png_composite_16(v, g, a, png_ptr->background.gray); png_composite_16(v, g, a, png_ptr->background.gray);
*sp = (png_byte)((v >> 8) & 0xff); *sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff); *(sp + 1) = (png_byte)(v & 0xff);
}
} }
} }
} }
break;
} }
break;
}
case PNG_COLOR_TYPE_RGB_ALPHA: case PNG_COLOR_TYPE_RGB_ALPHA:
{
if (row_info->bit_depth == 8)
{ {
if (row_info->bit_depth == 8)
{
#ifdef PNG_READ_GAMMA_SUPPORTED #ifdef PNG_READ_GAMMA_SUPPORTED
if (gamma_to_1 != NULL && gamma_from_1 != NULL && if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
gamma_table != NULL) gamma_table != NULL)
{
sp = row;
for (i = 0; i < row_width; i++, sp += 4)
{ {
sp = row; png_byte a = *(sp + 3);
for (i = 0; i < row_width; i++, sp += 4)
if (a == 0xff)
{ {
png_byte a = *(sp + 3); *sp = gamma_table[*sp];
*(sp + 1) = gamma_table[*(sp + 1)];
*(sp + 2) = gamma_table[*(sp + 2)];
}
if (a == 0xff) else if (a == 0)
{ {
*sp = gamma_table[*sp]; /* Background is already in screen gamma */
*(sp + 1) = gamma_table[*(sp + 1)]; *sp = (png_byte)png_ptr->background.red;
*(sp + 2) = gamma_table[*(sp + 2)]; *(sp + 1) = (png_byte)png_ptr->background.green;
} *(sp + 2) = (png_byte)png_ptr->background.blue;
}
else if (a == 0) else
{ {
/* Background is already in screen gamma */ png_byte v, w;
*sp = (png_byte)png_ptr->background.red;
*(sp + 1) = (png_byte)png_ptr->background.green;
*(sp + 2) = (png_byte)png_ptr->background.blue;
}
else v = gamma_to_1[*sp];
{ png_composite(w, v, a, png_ptr->background_1.red);
png_byte v, w; if (optimize == 0) w = gamma_from_1[w];
*sp = w;
v = gamma_to_1[*sp];
png_composite(w, v, a, png_ptr->background_1.red); v = gamma_to_1[*(sp + 1)];
if (optimize == 0) w = gamma_from_1[w]; png_composite(w, v, a, png_ptr->background_1.green);
*sp = w; if (optimize == 0) w = gamma_from_1[w];
*(sp + 1) = w;
v = gamma_to_1[*(sp + 1)];
png_composite(w, v, a, png_ptr->background_1.green); v = gamma_to_1[*(sp + 2)];
if (optimize == 0) w = gamma_from_1[w]; png_composite(w, v, a, png_ptr->background_1.blue);
*(sp + 1) = w; if (optimize == 0) w = gamma_from_1[w];
*(sp + 2) = w;
v = gamma_to_1[*(sp + 2)];
png_composite(w, v, a, png_ptr->background_1.blue);
if (optimize == 0) w = gamma_from_1[w];
*(sp + 2) = w;
}
} }
} }
else }
else
#endif #endif
{
sp = row;
for (i = 0; i < row_width; i++, sp += 4)
{ {
sp = row; png_byte a = *(sp + 3);
for (i = 0; i < row_width; i++, sp += 4)
{
png_byte a = *(sp + 3);
if (a == 0) if (a == 0)
{ {
*sp = (png_byte)png_ptr->background.red; *sp = (png_byte)png_ptr->background.red;
*(sp + 1) = (png_byte)png_ptr->background.green; *(sp + 1) = (png_byte)png_ptr->background.green;
*(sp + 2) = (png_byte)png_ptr->background.blue; *(sp + 2) = (png_byte)png_ptr->background.blue;
} }
else if (a < 0xff) else if (a < 0xff)
{ {
png_composite(*sp, *sp, a, png_ptr->background.red); png_composite(*sp, *sp, a, png_ptr->background.red);
png_composite(*(sp + 1), *(sp + 1), a, png_composite(*(sp + 1), *(sp + 1), a,
png_ptr->background.green); png_ptr->background.green);
png_composite(*(sp + 2), *(sp + 2), a, png_composite(*(sp + 2), *(sp + 2), a,
png_ptr->background.blue); png_ptr->background.blue);
}
} }
} }
} }
else /* if (row_info->bit_depth == 16) */ }
{ else /* if (row_info->bit_depth == 16) */
{
#ifdef PNG_READ_GAMMA_SUPPORTED #ifdef PNG_READ_GAMMA_SUPPORTED
if (gamma_16 != NULL && gamma_16_from_1 != NULL && if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
gamma_16_to_1 != NULL) gamma_16_to_1 != NULL)
{
sp = row;
for (i = 0; i < row_width; i++, sp += 8)
{ {
sp = row; png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
for (i = 0; i < row_width; i++, sp += 8) << 8) + (png_uint_16)(*(sp + 7)));
{
png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
<< 8) + (png_uint_16)(*(sp + 7)));
if (a == (png_uint_16)0xffff) if (a == (png_uint_16)0xffff)
{ {
png_uint_16 v; png_uint_16 v;
v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
*sp = (png_byte)((v >> 8) & 0xff); *sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff); *(sp + 1) = (png_byte)(v & 0xff);
v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)]; v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
*(sp + 2) = (png_byte)((v >> 8) & 0xff); *(sp + 2) = (png_byte)((v >> 8) & 0xff);
*(sp + 3) = (png_byte)(v & 0xff); *(sp + 3) = (png_byte)(v & 0xff);
v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)]; v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
*(sp + 4) = (png_byte)((v >> 8) & 0xff); *(sp + 4) = (png_byte)((v >> 8) & 0xff);
*(sp + 5) = (png_byte)(v & 0xff); *(sp + 5) = (png_byte)(v & 0xff);
} }
else if (a == 0) else if (a == 0)
{ {
/* Background is already in screen gamma */ /* Background is already in screen gamma */
*sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
*(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
*(sp + 2) = (png_byte)((png_ptr->background.green >> 8) *(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
& 0xff); & 0xff);
*(sp + 3) = (png_byte)(png_ptr->background.green *(sp + 3) = (png_byte)(png_ptr->background.green
& 0xff); & 0xff);
*(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
& 0xff); & 0xff);
*(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff); *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
} }
else else
{ {
png_uint_16 v, w; png_uint_16 v, w;
v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp]; v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
png_composite_16(w, v, a, png_ptr->background_1.red); png_composite_16(w, v, a, png_ptr->background_1.red);
if (optimize == 0) if (optimize == 0)
w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >> w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >>
8]; 8];
*sp = (png_byte)((w >> 8) & 0xff); *sp = (png_byte)((w >> 8) & 0xff);
*(sp + 1) = (png_byte)(w & 0xff); *(sp + 1) = (png_byte)(w & 0xff);
v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)]; v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
png_composite_16(w, v, a, png_ptr->background_1.green); png_composite_16(w, v, a, png_ptr->background_1.green);
if (optimize == 0) if (optimize == 0)
w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >> w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >>
8]; 8];
*(sp + 2) = (png_byte)((w >> 8) & 0xff); *(sp + 2) = (png_byte)((w >> 8) & 0xff);
*(sp + 3) = (png_byte)(w & 0xff); *(sp + 3) = (png_byte)(w & 0xff);
v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)]; v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
png_composite_16(w, v, a, png_ptr->background_1.blue); png_composite_16(w, v, a, png_ptr->background_1.blue);
if (optimize == 0) if (optimize == 0)
w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >> w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >>
8]; 8];
*(sp + 4) = (png_byte)((w >> 8) & 0xff); *(sp + 4) = (png_byte)((w >> 8) & 0xff);
*(sp + 5) = (png_byte)(w & 0xff); *(sp + 5) = (png_byte)(w & 0xff);
}
} }
} }
}
else else
#endif #endif
{
sp = row;
for (i = 0; i < row_width; i++, sp += 8)
{ {
sp = row; png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
for (i = 0; i < row_width; i++, sp += 8) << 8) + (png_uint_16)(*(sp + 7)));
{
png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
<< 8) + (png_uint_16)(*(sp + 7)));
if (a == 0) if (a == 0)
{ {
*sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
*(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
*(sp + 2) = (png_byte)((png_ptr->background.green >> 8) *(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
& 0xff); & 0xff);
*(sp + 3) = (png_byte)(png_ptr->background.green *(sp + 3) = (png_byte)(png_ptr->background.green
& 0xff); & 0xff);
*(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
& 0xff); & 0xff);
*(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff); *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
} }
else if (a < 0xffff) else if (a < 0xffff)
{ {
png_uint_16 v; png_uint_16 v;
png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1)); png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8) png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
+ *(sp + 3)); + *(sp + 3));
png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8) png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
+ *(sp + 5)); + *(sp + 5));
png_composite_16(v, r, a, png_ptr->background.red); png_composite_16(v, r, a, png_ptr->background.red);
*sp = (png_byte)((v >> 8) & 0xff); *sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff); *(sp + 1) = (png_byte)(v & 0xff);
png_composite_16(v, g, a, png_ptr->background.green); png_composite_16(v, g, a, png_ptr->background.green);
*(sp + 2) = (png_byte)((v >> 8) & 0xff); *(sp + 2) = (png_byte)((v >> 8) & 0xff);
*(sp + 3) = (png_byte)(v & 0xff); *(sp + 3) = (png_byte)(v & 0xff);
png_composite_16(v, b, a, png_ptr->background.blue); png_composite_16(v, b, a, png_ptr->background.blue);
*(sp + 4) = (png_byte)((v >> 8) & 0xff); *(sp + 4) = (png_byte)((v >> 8) & 0xff);
*(sp + 5) = (png_byte)(v & 0xff); *(sp + 5) = (png_byte)(v & 0xff);
}
} }
} }
} }
break;
} }
break;
default:
break;
} }
default:
break;
} }
} }
#endif /* READ_BACKGROUND || READ_ALPHA_MODE */ #endif /* READ_BACKGROUND || READ_ALPHA_MODE */
...@@ -4245,8 +4245,8 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row, ...@@ -4245,8 +4245,8 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
{ {
case 1: case 1:
{ {
sp = row + (png_size_t)((row_width - 1) >> 3); sp = row + (size_t)((row_width - 1) >> 3);
dp = row + (png_size_t)row_width - 1; dp = row + (size_t)row_width - 1;
shift = 7 - (int)((row_width + 7) & 0x07); shift = 7 - (int)((row_width + 7) & 0x07);
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
...@@ -4272,8 +4272,8 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row, ...@@ -4272,8 +4272,8 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
case 2: case 2:
{ {
sp = row + (png_size_t)((row_width - 1) >> 2); sp = row + (size_t)((row_width - 1) >> 2);
dp = row + (png_size_t)row_width - 1; dp = row + (size_t)row_width - 1;
shift = (int)((3 - ((row_width + 3) & 0x03)) << 1); shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
...@@ -4295,8 +4295,8 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row, ...@@ -4295,8 +4295,8 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
case 4: case 4:
{ {
sp = row + (png_size_t)((row_width - 1) >> 1); sp = row + (size_t)((row_width - 1) >> 1);
dp = row + (png_size_t)row_width - 1; dp = row + (size_t)row_width - 1;
shift = (int)((row_width & 0x01) << 2); shift = (int)((row_width & 0x01) << 2);
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
...@@ -4329,8 +4329,8 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row, ...@@ -4329,8 +4329,8 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
{ {
if (num_trans > 0) if (num_trans > 0)
{ {
sp = row + (png_size_t)row_width - 1; sp = row + (size_t)row_width - 1;
dp = row + (png_size_t)(row_width << 2) - 1; dp = row + ((size_t)row_width << 2) - 1;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
...@@ -4354,8 +4354,8 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row, ...@@ -4354,8 +4354,8 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
else else
{ {
sp = row + (png_size_t)row_width - 1; sp = row + (size_t)row_width - 1;
dp = row + (png_size_t)(row_width * 3) - 1; dp = row + (size_t)(row_width * 3) - 1;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
...@@ -4390,195 +4390,130 @@ png_do_expand(png_row_infop row_info, png_bytep row, ...@@ -4390,195 +4390,130 @@ png_do_expand(png_row_infop row_info, png_bytep row,
png_debug(1, "in png_do_expand"); png_debug(1, "in png_do_expand");
if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
{ {
if (row_info->color_type == PNG_COLOR_TYPE_GRAY) unsigned int gray = trans_color != NULL ? trans_color->gray : 0;
{
unsigned int gray = trans_color != NULL ? trans_color->gray : 0;
if (row_info->bit_depth < 8) if (row_info->bit_depth < 8)
{
switch (row_info->bit_depth)
{ {
switch (row_info->bit_depth) case 1:
{ {
case 1: gray = (gray & 0x01) * 0xff;
sp = row + (size_t)((row_width - 1) >> 3);
dp = row + (size_t)row_width - 1;
shift = 7 - (int)((row_width + 7) & 0x07);
for (i = 0; i < row_width; i++)
{ {
gray = (gray & 0x01) * 0xff; if ((*sp >> shift) & 0x01)
sp = row + (png_size_t)((row_width - 1) >> 3); *dp = 0xff;
dp = row + (png_size_t)row_width - 1;
shift = 7 - (int)((row_width + 7) & 0x07);
for (i = 0; i < row_width; i++)
{
if ((*sp >> shift) & 0x01)
*dp = 0xff;
else
*dp = 0;
if (shift == 7)
{
shift = 0;
sp--;
}
else
shift++;
dp--; else
} *dp = 0;
break;
}
case 2: if (shift == 7)
{
gray = (gray & 0x03) * 0x55;
sp = row + (png_size_t)((row_width - 1) >> 2);
dp = row + (png_size_t)row_width - 1;
shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
for (i = 0; i < row_width; i++)
{ {
value = (*sp >> shift) & 0x03; shift = 0;
*dp = (png_byte)(value | (value << 2) | (value << 4) | sp--;
(value << 6));
if (shift == 6)
{
shift = 0;
sp--;
}
else
shift += 2;
dp--;
} }
break;
}
case 4:
{
gray = (gray & 0x0f) * 0x11;
sp = row + (png_size_t)((row_width - 1) >> 1);
dp = row + (png_size_t)row_width - 1;
shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
for (i = 0; i < row_width; i++)
{
value = (*sp >> shift) & 0x0f;
*dp = (png_byte)(value | (value << 4));
if (shift == 4)
{
shift = 0;
sp--;
}
else else
shift = 4; shift++;
dp--; dp--;
}
break;
} }
break;
default:
break;
} }
row_info->bit_depth = 8; case 2:
row_info->pixel_depth = 8;
row_info->rowbytes = row_width;
}
if (trans_color != NULL)
{
if (row_info->bit_depth == 8)
{ {
gray = gray & 0xff; gray = (gray & 0x03) * 0x55;
sp = row + (png_size_t)row_width - 1; sp = row + (size_t)((row_width - 1) >> 2);
dp = row + (png_size_t)(row_width << 1) - 1; dp = row + (size_t)row_width - 1;
shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
if ((*sp & 0xffU) == gray) value = (*sp >> shift) & 0x03;
*dp-- = 0; *dp = (png_byte)(value | (value << 2) | (value << 4) |
(value << 6));
if (shift == 6)
{
shift = 0;
sp--;
}
else else
*dp-- = 0xff; shift += 2;
*dp-- = *sp--; dp--;
} }
break;
} }
else if (row_info->bit_depth == 16) case 4:
{ {
unsigned int gray_high = (gray >> 8) & 0xff; gray = (gray & 0x0f) * 0x11;
unsigned int gray_low = gray & 0xff; sp = row + (size_t)((row_width - 1) >> 1);
sp = row + row_info->rowbytes - 1; dp = row + (size_t)row_width - 1;
dp = row + (row_info->rowbytes << 1) - 1; shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
if ((*(sp - 1) & 0xffU) == gray_high && value = (*sp >> shift) & 0x0f;
(*(sp) & 0xffU) == gray_low) *dp = (png_byte)(value | (value << 4));
if (shift == 4)
{ {
*dp-- = 0; shift = 0;
*dp-- = 0; sp--;
} }
else else
{ shift = 4;
*dp-- = 0xff;
*dp-- = 0xff;
}
*dp-- = *sp--; dp--;
*dp-- = *sp--;
} }
break;
} }
row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA; default:
row_info->channels = 2; break;
row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
row_width);
} }
row_info->bit_depth = 8;
row_info->pixel_depth = 8;
row_info->rowbytes = row_width;
} }
else if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
trans_color != NULL) if (trans_color != NULL)
{ {
if (row_info->bit_depth == 8) if (row_info->bit_depth == 8)
{ {
png_byte red = (png_byte)(trans_color->red & 0xff); gray = gray & 0xff;
png_byte green = (png_byte)(trans_color->green & 0xff); sp = row + (size_t)row_width - 1;
png_byte blue = (png_byte)(trans_color->blue & 0xff); dp = row + ((size_t)row_width << 1) - 1;
sp = row + (png_size_t)row_info->rowbytes - 1;
dp = row + (png_size_t)(row_width << 2) - 1;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue) if ((*sp & 0xffU) == gray)
*dp-- = 0; *dp-- = 0;
else else
*dp-- = 0xff; *dp-- = 0xff;
*dp-- = *sp--; *dp-- = *sp--;
*dp-- = *sp--;
*dp-- = *sp--;
} }
} }
else if (row_info->bit_depth == 16) else if (row_info->bit_depth == 16)
{ {
png_byte red_high = (png_byte)((trans_color->red >> 8) & 0xff); unsigned int gray_high = (gray >> 8) & 0xff;
png_byte green_high = (png_byte)((trans_color->green >> 8) & 0xff); unsigned int gray_low = gray & 0xff;
png_byte blue_high = (png_byte)((trans_color->blue >> 8) & 0xff);
png_byte red_low = (png_byte)(trans_color->red & 0xff);
png_byte green_low = (png_byte)(trans_color->green & 0xff);
png_byte blue_low = (png_byte)(trans_color->blue & 0xff);
sp = row + row_info->rowbytes - 1; sp = row + row_info->rowbytes - 1;
dp = row + (png_size_t)(row_width << 3) - 1; dp = row + (row_info->rowbytes << 1) - 1;
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
if (*(sp - 5) == red_high && if ((*(sp - 1) & 0xffU) == gray_high &&
*(sp - 4) == red_low && (*(sp) & 0xffU) == gray_low)
*(sp - 3) == green_high &&
*(sp - 2) == green_low &&
*(sp - 1) == blue_high &&
*(sp ) == blue_low)
{ {
*dp-- = 0; *dp-- = 0;
*dp-- = 0; *dp-- = 0;
...@@ -4592,17 +4527,80 @@ png_do_expand(png_row_infop row_info, png_bytep row, ...@@ -4592,17 +4527,80 @@ png_do_expand(png_row_infop row_info, png_bytep row,
*dp-- = *sp--; *dp-- = *sp--;
*dp-- = *sp--; *dp-- = *sp--;
*dp-- = *sp--;
*dp-- = *sp--;
*dp-- = *sp--;
*dp-- = *sp--;
} }
} }
row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
row_info->channels = 4; row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2); row_info->channels = 2;
row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
row_width);
}
}
else if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
trans_color != NULL)
{
if (row_info->bit_depth == 8)
{
png_byte red = (png_byte)(trans_color->red & 0xff);
png_byte green = (png_byte)(trans_color->green & 0xff);
png_byte blue = (png_byte)(trans_color->blue & 0xff);
sp = row + (size_t)row_info->rowbytes - 1;
dp = row + ((size_t)row_width << 2) - 1;
for (i = 0; i < row_width; i++)
{
if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
*dp-- = 0;
else
*dp-- = 0xff;
*dp-- = *sp--;
*dp-- = *sp--;
*dp-- = *sp--;
}
}
else if (row_info->bit_depth == 16)
{
png_byte red_high = (png_byte)((trans_color->red >> 8) & 0xff);
png_byte green_high = (png_byte)((trans_color->green >> 8) & 0xff);
png_byte blue_high = (png_byte)((trans_color->blue >> 8) & 0xff);
png_byte red_low = (png_byte)(trans_color->red & 0xff);
png_byte green_low = (png_byte)(trans_color->green & 0xff);
png_byte blue_low = (png_byte)(trans_color->blue & 0xff);
sp = row + row_info->rowbytes - 1;
dp = row + ((size_t)row_width << 3) - 1;
for (i = 0; i < row_width; i++)
{
if (*(sp - 5) == red_high &&
*(sp - 4) == red_low &&
*(sp - 3) == green_high &&
*(sp - 2) == green_low &&
*(sp - 1) == blue_high &&
*(sp ) == blue_low)
{
*dp-- = 0;
*dp-- = 0;
}
else
{
*dp-- = 0xff;
*dp-- = 0xff;
}
*dp-- = *sp--;
*dp-- = *sp--;
*dp-- = *sp--;
*dp-- = *sp--;
*dp-- = *sp--;
*dp-- = *sp--;
}
} }
row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
row_info->channels = 4;
row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
} }
} }
#endif #endif
...@@ -4629,7 +4627,9 @@ png_do_expand_16(png_row_infop row_info, png_bytep row) ...@@ -4629,7 +4627,9 @@ png_do_expand_16(png_row_infop row_info, png_bytep row)
png_byte *sp = row + row_info->rowbytes; /* source, last byte + 1 */ png_byte *sp = row + row_info->rowbytes; /* source, last byte + 1 */
png_byte *dp = sp + row_info->rowbytes; /* destination, end + 1 */ png_byte *dp = sp + row_info->rowbytes; /* destination, end + 1 */
while (dp > sp) while (dp > sp)
dp[-2] = dp[-1] = *--sp, dp -= 2; {
dp[-2] = dp[-1] = *--sp; dp -= 2;
}
row_info->rowbytes *= 2; row_info->rowbytes *= 2;
row_info->bit_depth = 16; row_info->bit_depth = 16;
...@@ -4783,8 +4783,7 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info) ...@@ -4783,8 +4783,7 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
&(png_ptr->trans_color)); &(png_ptr->trans_color));
else else
png_do_expand(row_info, png_ptr->row_buf + 1, png_do_expand(row_info, png_ptr->row_buf + 1, NULL);
NULL);
} }
} }
#endif #endif
...@@ -5008,7 +5007,7 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info) ...@@ -5008,7 +5007,7 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
(png_ptr, /* png_ptr */ (png_ptr, /* png_ptr */
row_info, /* row_info: */ row_info, /* row_info: */
/* png_uint_32 width; width of row */ /* png_uint_32 width; width of row */
/* png_size_t rowbytes; number of bytes in row */ /* size_t rowbytes; number of bytes in row */
/* png_byte color_type; color type of pixels */ /* png_byte color_type; color type of pixels */
/* png_byte bit_depth; bit depth of samples */ /* png_byte bit_depth; bit depth of samples */
/* png_byte channels; number of channels (1-4) */ /* png_byte channels; number of channels (1-4) */
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
* However, the following notice accompanied the original version of this * However, the following notice accompanied the original version of this
* file and, per its terms, should not be removed: * file and, per its terms, should not be removed:
* *
* Last changed in libpng 1.6.27 [January 5, 2017] * Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
...@@ -130,7 +130,7 @@ png_get_int_32)(png_const_bytep buf) ...@@ -130,7 +130,7 @@ png_get_int_32)(png_const_bytep buf)
png_uint_16 (PNGAPI png_uint_16 (PNGAPI
png_get_uint_16)(png_const_bytep buf) png_get_uint_16)(png_const_bytep buf)
{ {
/* ANSI-C requires an int value to accomodate at least 16 bits so this /* ANSI-C requires an int value to accommodate at least 16 bits so this
* works and allows the compiler not to worry about possible narrowing * works and allows the compiler not to worry about possible narrowing
* on 32-bit systems. (Pre-ANSI systems did not make integers smaller * on 32-bit systems. (Pre-ANSI systems did not make integers smaller
* than 16 bits either.) * than 16 bits either.)
...@@ -148,7 +148,7 @@ png_get_uint_16)(png_const_bytep buf) ...@@ -148,7 +148,7 @@ png_get_uint_16)(png_const_bytep buf)
void /* PRIVATE */ void /* PRIVATE */
png_read_sig(png_structrp png_ptr, png_inforp info_ptr) png_read_sig(png_structrp png_ptr, png_inforp info_ptr)
{ {
png_size_t num_checked, num_to_check; size_t num_checked, num_to_check;
/* Exit if the user application does not expect a signature. */ /* Exit if the user application does not expect a signature. */
if (png_ptr->sig_bytes >= 8) if (png_ptr->sig_bytes >= 8)
...@@ -209,6 +209,9 @@ png_read_chunk_header(png_structrp png_ptr) ...@@ -209,6 +209,9 @@ png_read_chunk_header(png_structrp png_ptr)
/* Check to see if chunk name is valid. */ /* Check to see if chunk name is valid. */
png_check_chunk_name(png_ptr, png_ptr->chunk_name); png_check_chunk_name(png_ptr, png_ptr->chunk_name);
/* Check for too-large chunk length */
png_check_chunk_length(png_ptr, length);
#ifdef PNG_IO_STATE_SUPPORTED #ifdef PNG_IO_STATE_SUPPORTED
png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_DATA; png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_DATA;
#endif #endif
...@@ -339,6 +342,7 @@ png_read_buffer(png_structrp png_ptr, png_alloc_size_t new_size, int warn) ...@@ -339,6 +342,7 @@ png_read_buffer(png_structrp png_ptr, png_alloc_size_t new_size, int warn)
if (buffer != NULL) if (buffer != NULL)
{ {
memset(buffer, 0, new_size); /* just in case */
png_ptr->read_buffer = buffer; png_ptr->read_buffer = buffer;
png_ptr->read_buffer_size = new_size; png_ptr->read_buffer_size = new_size;
} }
...@@ -446,7 +450,7 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner) ...@@ -446,7 +450,7 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED; png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED;
} }
#if ZLIB_VERNUM >= 0x1281 && \ #if ZLIB_VERNUM >= 0x1290 && \
defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_IGNORE_ADLER32) defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_IGNORE_ADLER32)
if (((png_ptr->options >> PNG_IGNORE_ADLER32) & 3) == PNG_OPTION_ON) if (((png_ptr->options >> PNG_IGNORE_ADLER32) & 3) == PNG_OPTION_ON)
/* Turn off validation of the ADLER32 checksum in IDAT chunks */ /* Turn off validation of the ADLER32 checksum in IDAT chunks */
...@@ -698,6 +702,8 @@ png_decompress_chunk(png_structrp png_ptr, ...@@ -698,6 +702,8 @@ png_decompress_chunk(png_structrp png_ptr,
if (text != NULL) if (text != NULL)
{ {
memset(text, 0, buffer_size);
ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/, ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,
png_ptr->read_buffer + prefix_size, &lzsize, png_ptr->read_buffer + prefix_size, &lzsize,
text + prefix_size, newlength); text + prefix_size, newlength);
...@@ -761,9 +767,7 @@ png_decompress_chunk(png_structrp png_ptr, ...@@ -761,9 +767,7 @@ png_decompress_chunk(png_structrp png_ptr,
{ {
/* inflateReset failed, store the error message */ /* inflateReset failed, store the error message */
png_zstream_error(png_ptr, ret); png_zstream_error(png_ptr, ret);
ret = PNG_UNEXPECTED_ZLIB_RETURN;
if (ret == Z_STREAM_END)
ret = PNG_UNEXPECTED_ZLIB_RETURN;
} }
} }
...@@ -1405,11 +1409,13 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) ...@@ -1405,11 +1409,13 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
* chunk is just ignored, so does not invalidate the color space. An * chunk is just ignored, so does not invalidate the color space. An
* alternative is to set the 'invalid' flags at the start of this routine * alternative is to set the 'invalid' flags at the start of this routine
* and only clear them in they were not set before and all the tests pass. * and only clear them in they were not set before and all the tests pass.
* The minimum 'deflate' stream is assumed to be just the 2 byte header and
* 4 byte checksum. The keyword must be at least one character and there is
* a terminator (0) byte and the compression method.
*/ */
if (length < 9)
/* The keyword must be at least one character and there is a
* terminator (0) byte and the compression method byte, and the
* 'zlib' datastream is at least 11 bytes.
*/
if (length < 14)
{ {
png_crc_finish(png_ptr, length); png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "too short"); png_chunk_benign_error(png_ptr, "too short");
...@@ -1441,6 +1447,16 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) ...@@ -1441,6 +1447,16 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_crc_read(png_ptr, (png_bytep)keyword, read_length); png_crc_read(png_ptr, (png_bytep)keyword, read_length);
length -= read_length; length -= read_length;
/* The minimum 'zlib' stream is assumed to be just the 2 byte header,
* 5 bytes minimum 'deflate' stream, and the 4 byte checksum.
*/
if (length < 11)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "too short");
return;
}
keyword_length = 0; keyword_length = 0;
while (keyword_length < 80 && keyword_length < read_length && while (keyword_length < 80 && keyword_length < read_length &&
keyword[keyword_length] != 0) keyword[keyword_length] != 0)
...@@ -1459,7 +1475,7 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) ...@@ -1459,7 +1475,7 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
if (png_inflate_claim(png_ptr, png_iCCP) == Z_OK) if (png_inflate_claim(png_ptr, png_iCCP) == Z_OK)
{ {
Byte profile_header[132]; Byte profile_header[132]={0};
Byte local_buffer[PNG_INFLATE_BUF_SIZE]; Byte local_buffer[PNG_INFLATE_BUF_SIZE];
png_alloc_size_t size = (sizeof profile_header); png_alloc_size_t size = (sizeof profile_header);
...@@ -1489,7 +1505,7 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) ...@@ -1489,7 +1505,7 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
/* Now read the tag table; a variable size buffer is /* Now read the tag table; a variable size buffer is
* needed at this point, allocate one for the whole * needed at this point, allocate one for the whole
* profile. The header check has already validated * profile. The header check has already validated
* that none of these stuff will overflow. * that none of this stuff will overflow.
*/ */
const png_uint_32 tag_count = png_get_uint_32( const png_uint_32 tag_count = png_get_uint_32(
profile_header+128); profile_header+128);
...@@ -1596,19 +1612,11 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) ...@@ -1596,19 +1612,11 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
return; return;
} }
} }
if (errmsg == NULL)
else if (size > 0)
errmsg = "truncated";
#ifndef __COVERITY__
else
errmsg = png_ptr->zstream.msg; errmsg = png_ptr->zstream.msg;
#endif
} }
/* else png_icc_check_tag_table output an error */ /* else png_icc_check_tag_table output an error */
} }
else /* profile truncated */ else /* profile truncated */
errmsg = png_ptr->zstream.msg; errmsg = png_ptr->zstream.msg;
} }
...@@ -1668,7 +1676,7 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) ...@@ -1668,7 +1676,7 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
int entry_size, i; int entry_size, i;
png_uint_32 skip = 0; png_uint_32 skip = 0;
png_uint_32 dl; png_uint_32 dl;
png_size_t max_dl; size_t max_dl;
png_debug(1, "in png_handle_sPLT"); png_debug(1, "in png_handle_sPLT");
...@@ -2017,6 +2025,15 @@ png_handle_bKGD(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) ...@@ -2017,6 +2025,15 @@ png_handle_bKGD(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0) /* GRAY */ else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0) /* GRAY */
{ {
if (png_ptr->bit_depth <= 8)
{
if (buf[0] != 0 || buf[1] >= (unsigned int)(1 << png_ptr->bit_depth))
{
png_chunk_benign_error(png_ptr, "invalid gray level");
return;
}
}
background.index = 0; background.index = 0;
background.red = background.red =
background.green = background.green =
...@@ -2026,6 +2043,15 @@ png_handle_bKGD(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) ...@@ -2026,6 +2043,15 @@ png_handle_bKGD(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
else else
{ {
if (png_ptr->bit_depth <= 8)
{
if (buf[0] != 0 || buf[2] != 0 || buf[4] != 0)
{
png_chunk_benign_error(png_ptr, "invalid color");
return;
}
}
background.index = 0; background.index = 0;
background.red = png_get_uint_16(buf); background.red = png_get_uint_16(buf);
background.green = png_get_uint_16(buf + 2); background.green = png_get_uint_16(buf + 2);
...@@ -2037,6 +2063,69 @@ png_handle_bKGD(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) ...@@ -2037,6 +2063,69 @@ png_handle_bKGD(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
} }
#endif #endif
#ifdef PNG_READ_eXIf_SUPPORTED
void /* PRIVATE */
png_handle_eXIf(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
{
unsigned int i;
png_debug(1, "in png_handle_eXIf");
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
png_chunk_error(png_ptr, "missing IHDR");
if (length < 2)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "too short");
return;
}
else if (info_ptr == NULL || (info_ptr->valid & PNG_INFO_eXIf) != 0)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "duplicate");
return;
}
info_ptr->free_me |= PNG_FREE_EXIF;
info_ptr->eXIf_buf = png_voidcast(png_bytep,
png_malloc_warn(png_ptr, length));
if (info_ptr->eXIf_buf == NULL)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "out of memory");
return;
}
for (i = 0; i < length; i++)
{
png_byte buf[1];
png_crc_read(png_ptr, buf, 1);
info_ptr->eXIf_buf[i] = buf[0];
if (i == 1 && buf[0] != 'M' && buf[0] != 'I'
&& info_ptr->eXIf_buf[0] != buf[0])
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "incorrect byte-order specifier");
png_free(png_ptr, info_ptr->eXIf_buf);
info_ptr->eXIf_buf = NULL;
return;
}
}
if (png_crc_finish(png_ptr, 0) != 0)
return;
png_set_eXIf_1(png_ptr, info_ptr, length, info_ptr->eXIf_buf);
png_free(png_ptr, info_ptr->eXIf_buf);
info_ptr->eXIf_buf = NULL;
}
#endif
#ifdef PNG_READ_hIST_SUPPORTED #ifdef PNG_READ_hIST_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_handle_hIST(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) png_handle_hIST(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
...@@ -2316,7 +2405,7 @@ void /* PRIVATE */ ...@@ -2316,7 +2405,7 @@ void /* PRIVATE */
png_handle_sCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) png_handle_sCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
{ {
png_bytep buffer; png_bytep buffer;
png_size_t i; size_t i;
int state; int state;
png_debug(1, "in png_handle_sCAL"); png_debug(1, "in png_handle_sCAL");
...@@ -2386,7 +2475,7 @@ png_handle_sCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) ...@@ -2386,7 +2475,7 @@ png_handle_sCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
else else
{ {
png_size_t heighti = i; size_t heighti = i;
state = 0; state = 0;
if (png_check_fp_number((png_const_charp)buffer, length, if (png_check_fp_number((png_const_charp)buffer, length,
...@@ -2565,6 +2654,9 @@ png_handle_zTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) ...@@ -2565,6 +2654,9 @@ png_handle_zTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
png_ptr->mode |= PNG_AFTER_IDAT; png_ptr->mode |= PNG_AFTER_IDAT;
/* Note, "length" is sufficient here; we won't be adding
* a null terminator later.
*/
buffer = png_read_buffer(png_ptr, length, 2/*silent*/); buffer = png_read_buffer(png_ptr, length, 2/*silent*/);
if (buffer == NULL) if (buffer == NULL)
...@@ -2611,23 +2703,28 @@ png_handle_zTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) ...@@ -2611,23 +2703,28 @@ png_handle_zTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
{ {
png_text text; png_text text;
/* It worked; png_ptr->read_buffer now looks like a tEXt chunk except if (png_ptr->read_buffer == NULL)
* for the extra compression type byte and the fact that it isn't errmsg="Read failure in png_handle_zTXt";
* necessarily '\0' terminated. else
*/ {
buffer = png_ptr->read_buffer; /* It worked; png_ptr->read_buffer now looks like a tEXt chunk
buffer[uncompressed_length+(keyword_length+2)] = 0; * except for the extra compression type byte and the fact that
* it isn't necessarily '\0' terminated.
text.compression = PNG_TEXT_COMPRESSION_zTXt; */
text.key = (png_charp)buffer; buffer = png_ptr->read_buffer;
text.text = (png_charp)(buffer + keyword_length+2); buffer[uncompressed_length+(keyword_length+2)] = 0;
text.text_length = uncompressed_length;
text.itxt_length = 0; text.compression = PNG_TEXT_COMPRESSION_zTXt;
text.lang = NULL; text.key = (png_charp)buffer;
text.lang_key = NULL; text.text = (png_charp)(buffer + keyword_length+2);
text.text_length = uncompressed_length;
if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0) text.itxt_length = 0;
errmsg = "insufficient memory"; text.lang = NULL;
text.lang_key = NULL;
if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0)
errmsg = "insufficient memory";
}
} }
else else
...@@ -2816,7 +2913,7 @@ png_cache_unknown_chunk(png_structrp png_ptr, png_uint_32 length) ...@@ -2816,7 +2913,7 @@ png_cache_unknown_chunk(png_structrp png_ptr, png_uint_32 length)
{ {
PNG_CSTRING_FROM_CHUNK(png_ptr->unknown_chunk.name, png_ptr->chunk_name); PNG_CSTRING_FROM_CHUNK(png_ptr->unknown_chunk.name, png_ptr->chunk_name);
/* The following is safe because of the PNG_SIZE_MAX init above */ /* The following is safe because of the PNG_SIZE_MAX init above */
png_ptr->unknown_chunk.size = (png_size_t)length/*SAFE*/; png_ptr->unknown_chunk.size = (size_t)length/*SAFE*/;
/* 'mode' is a flag array, only the bottom four bits matter here */ /* 'mode' is a flag array, only the bottom four bits matter here */
png_ptr->unknown_chunk.location = (png_byte)png_ptr->mode/*SAFE*/; png_ptr->unknown_chunk.location = (png_byte)png_ptr->mode/*SAFE*/;
...@@ -3003,7 +3100,7 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr, ...@@ -3003,7 +3100,7 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
case 2: case 2:
png_ptr->user_chunk_cache_max = 1; png_ptr->user_chunk_cache_max = 1;
png_chunk_benign_error(png_ptr, "no space in chunk cache"); png_chunk_benign_error(png_ptr, "no space in chunk cache");
/* FALL THROUGH */ /* FALLTHROUGH */
case 1: case 1:
/* NOTE: prior to 1.6.0 this case resulted in an unknown critical /* NOTE: prior to 1.6.0 this case resulted in an unknown critical
* chunk being skipped, now there will be a hard error below. * chunk being skipped, now there will be a hard error below.
...@@ -3012,7 +3109,7 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr, ...@@ -3012,7 +3109,7 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
default: /* not at limit */ default: /* not at limit */
--(png_ptr->user_chunk_cache_max); --(png_ptr->user_chunk_cache_max);
/* FALL THROUGH */ /* FALLTHROUGH */
case 0: /* no limit */ case 0: /* no limit */
# endif /* USER_LIMITS */ # endif /* USER_LIMITS */
/* Here when the limit isn't reached or when limits are compiled /* Here when the limit isn't reached or when limits are compiled
...@@ -3063,20 +3160,61 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr, ...@@ -3063,20 +3160,61 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
*/ */
void /* PRIVATE */ void /* PRIVATE */
png_check_chunk_name(png_structrp png_ptr, png_uint_32 chunk_name) png_check_chunk_name(png_const_structrp png_ptr, const png_uint_32 chunk_name)
{ {
int i; int i;
png_uint_32 cn=chunk_name;
png_debug(1, "in png_check_chunk_name"); png_debug(1, "in png_check_chunk_name");
for (i=1; i<=4; ++i) for (i=1; i<=4; ++i)
{ {
int c = chunk_name & 0xff; int c = cn & 0xff;
if (c < 65 || c > 122 || (c > 90 && c < 97)) if (c < 65 || c > 122 || (c > 90 && c < 97))
png_chunk_error(png_ptr, "invalid chunk type"); png_chunk_error(png_ptr, "invalid chunk type");
chunk_name >>= 8; cn >>= 8;
}
}
void /* PRIVATE */
png_check_chunk_length(png_const_structrp png_ptr, const png_uint_32 length)
{
png_alloc_size_t limit = PNG_UINT_31_MAX;
# ifdef PNG_SET_USER_LIMITS_SUPPORTED
if (png_ptr->user_chunk_malloc_max > 0 &&
png_ptr->user_chunk_malloc_max < limit)
limit = png_ptr->user_chunk_malloc_max;
# elif PNG_USER_CHUNK_MALLOC_MAX > 0
if (PNG_USER_CHUNK_MALLOC_MAX < limit)
limit = PNG_USER_CHUNK_MALLOC_MAX;
# endif
if (png_ptr->chunk_name == png_IDAT)
{
png_alloc_size_t idat_limit = PNG_UINT_31_MAX;
size_t row_factor =
(size_t)png_ptr->width
* (size_t)png_ptr->channels
* (png_ptr->bit_depth > 8? 2: 1)
+ 1
+ (png_ptr->interlaced? 6: 0);
if (png_ptr->height > PNG_UINT_32_MAX/row_factor)
idat_limit = PNG_UINT_31_MAX;
else
idat_limit = png_ptr->height * row_factor;
row_factor = row_factor > 32566? 32566 : row_factor;
idat_limit += 6 + 5*(idat_limit/row_factor+1); /* zlib+deflate overhead */
idat_limit=idat_limit < PNG_UINT_31_MAX? idat_limit : PNG_UINT_31_MAX;
limit = limit < idat_limit? idat_limit : limit;
}
if (length > limit)
{
png_debug2(0," length = %lu, limit = %lu",
(unsigned long)length,(unsigned long)limit);
png_chunk_error(png_ptr, "chunk data is too large");
} }
} }
...@@ -3405,7 +3543,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display) ...@@ -3405,7 +3543,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
*/ */
do do
{ {
dp[0] = sp[0], dp[1] = sp[1]; dp[0] = sp[0]; dp[1] = sp[1];
if (row_width <= bytes_to_jump) if (row_width <= bytes_to_jump)
return; return;
...@@ -3426,7 +3564,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display) ...@@ -3426,7 +3564,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
*/ */
for (;;) for (;;)
{ {
dp[0] = sp[0], dp[1] = sp[1], dp[2] = sp[2]; dp[0] = sp[0]; dp[1] = sp[1]; dp[2] = sp[2];
if (row_width <= bytes_to_jump) if (row_width <= bytes_to_jump)
return; return;
...@@ -3590,8 +3728,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, ...@@ -3590,8 +3728,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
{ {
case 1: case 1:
{ {
png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3); png_bytep sp = row + (size_t)((row_info->width - 1) >> 3);
png_bytep dp = row + (png_size_t)((final_width - 1) >> 3); png_bytep dp = row + (size_t)((final_width - 1) >> 3);
unsigned int sshift, dshift; unsigned int sshift, dshift;
unsigned int s_start, s_end; unsigned int s_start, s_end;
int s_inc; int s_inc;
...@@ -3717,8 +3855,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, ...@@ -3717,8 +3855,8 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
case 4: case 4:
{ {
png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1); png_bytep sp = row + (size_t)((row_info->width - 1) >> 1);
png_bytep dp = row + (png_size_t)((final_width - 1) >> 1); png_bytep dp = row + (size_t)((final_width - 1) >> 1);
unsigned int sshift, dshift; unsigned int sshift, dshift;
unsigned int s_start, s_end; unsigned int s_start, s_end;
int s_inc; int s_inc;
...@@ -3780,12 +3918,12 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, ...@@ -3780,12 +3918,12 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
default: default:
{ {
png_size_t pixel_bytes = (row_info->pixel_depth >> 3); size_t pixel_bytes = (row_info->pixel_depth >> 3);
png_bytep sp = row + (png_size_t)(row_info->width - 1) png_bytep sp = row + (size_t)(row_info->width - 1)
* pixel_bytes; * pixel_bytes;
png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes; png_bytep dp = row + (size_t)(final_width - 1) * pixel_bytes;
int jstop = (int)png_pass_inc[pass]; int jstop = (int)png_pass_inc[pass];
png_uint_32 i; png_uint_32 i;
...@@ -3822,8 +3960,8 @@ static void ...@@ -3822,8 +3960,8 @@ static void
png_read_filter_row_sub(png_row_infop row_info, png_bytep row, png_read_filter_row_sub(png_row_infop row_info, png_bytep row,
png_const_bytep prev_row) png_const_bytep prev_row)
{ {
png_size_t i; size_t i;
png_size_t istop = row_info->rowbytes; size_t istop = row_info->rowbytes;
unsigned int bpp = (row_info->pixel_depth + 7) >> 3; unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
png_bytep rp = row + bpp; png_bytep rp = row + bpp;
...@@ -3840,8 +3978,8 @@ static void ...@@ -3840,8 +3978,8 @@ static void
png_read_filter_row_up(png_row_infop row_info, png_bytep row, png_read_filter_row_up(png_row_infop row_info, png_bytep row,
png_const_bytep prev_row) png_const_bytep prev_row)
{ {
png_size_t i; size_t i;
png_size_t istop = row_info->rowbytes; size_t istop = row_info->rowbytes;
png_bytep rp = row; png_bytep rp = row;
png_const_bytep pp = prev_row; png_const_bytep pp = prev_row;
...@@ -3856,11 +3994,11 @@ static void ...@@ -3856,11 +3994,11 @@ static void
png_read_filter_row_avg(png_row_infop row_info, png_bytep row, png_read_filter_row_avg(png_row_infop row_info, png_bytep row,
png_const_bytep prev_row) png_const_bytep prev_row)
{ {
png_size_t i; size_t i;
png_bytep rp = row; png_bytep rp = row;
png_const_bytep pp = prev_row; png_const_bytep pp = prev_row;
unsigned int bpp = (row_info->pixel_depth + 7) >> 3; unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
png_size_t istop = row_info->rowbytes - bpp; size_t istop = row_info->rowbytes - bpp;
for (i = 0; i < bpp; i++) for (i = 0; i < bpp; i++)
{ {
...@@ -3915,7 +4053,10 @@ png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row, ...@@ -3915,7 +4053,10 @@ png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row,
/* Find the best predictor, the least of pa, pb, pc favoring the earlier /* Find the best predictor, the least of pa, pb, pc favoring the earlier
* ones in the case of a tie. * ones in the case of a tie.
*/ */
if (pb < pa) pa = pb, a = b; if (pb < pa)
{
pa = pb; a = b;
}
if (pc < pa) a = c; if (pc < pa) a = c;
/* Calculate the current pixel in a, and move the previous row pixel to c /* Calculate the current pixel in a, and move the previous row pixel to c
...@@ -3967,7 +4108,10 @@ png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row, ...@@ -3967,7 +4108,10 @@ png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row,
pc = (p + pc) < 0 ? -(p + pc) : p + pc; pc = (p + pc) < 0 ? -(p + pc) : p + pc;
#endif #endif
if (pb < pa) pa = pb, a = b; if (pb < pa)
{
pa = pb; a = b;
}
if (pc < pa) a = c; if (pc < pa) a = c;
a += *row; a += *row;
...@@ -4290,7 +4434,7 @@ png_read_start_row(png_structrp png_ptr) ...@@ -4290,7 +4434,7 @@ png_read_start_row(png_structrp png_ptr)
static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
unsigned int max_pixel_depth; unsigned int max_pixel_depth;
png_size_t row_bytes; size_t row_bytes;
png_debug(1, "in png_read_start_row"); png_debug(1, "in png_read_start_row");
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
* However, the following notice accompanied the original version of this * However, the following notice accompanied the original version of this
* file and, per its terms, should not be removed: * file and, per its terms, should not be removed:
* *
* Last changed in libpng 1.6.26 [October 20, 2016] * Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 1998-2016 Glenn Randers-Pehrson * Copyright (c) 1998-2018 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
...@@ -162,6 +162,53 @@ png_set_cHRM_XYZ(png_const_structrp png_ptr, png_inforp info_ptr, double red_X, ...@@ -162,6 +162,53 @@ png_set_cHRM_XYZ(png_const_structrp png_ptr, png_inforp info_ptr, double red_X,
#endif /* cHRM */ #endif /* cHRM */
#ifdef PNG_eXIf_SUPPORTED
void PNGAPI
png_set_eXIf(png_const_structrp png_ptr, png_inforp info_ptr,
const png_bytep eXIf_buf)
{
png_warning(png_ptr, "png_set_eXIf does not work; use png_set_eXIf_1");
PNG_UNUSED(info_ptr)
PNG_UNUSED(eXIf_buf)
}
void PNGAPI
png_set_eXIf_1(png_const_structrp png_ptr, png_inforp info_ptr,
const png_uint_32 num_exif, const png_bytep eXIf_buf)
{
int i;
png_debug1(1, "in %s storage function", "eXIf");
if (png_ptr == NULL || info_ptr == NULL)
return;
if (info_ptr->exif)
{
png_free(png_ptr, info_ptr->exif);
info_ptr->exif = NULL;
}
info_ptr->num_exif = num_exif;
info_ptr->exif = png_voidcast(png_bytep, png_malloc_warn(png_ptr,
info_ptr->num_exif));
if (info_ptr->exif == NULL)
{
png_warning(png_ptr, "Insufficient memory for eXIf chunk data");
return;
}
info_ptr->free_me |= PNG_FREE_EXIF;
for (i = 0; i < (int) info_ptr->num_exif; i++)
info_ptr->exif[i] = eXIf_buf[i];
info_ptr->valid |= PNG_INFO_eXIf;
}
#endif /* eXIf */
#ifdef PNG_gAMA_SUPPORTED #ifdef PNG_gAMA_SUPPORTED
void PNGFAPI void PNGFAPI
png_set_gAMA_fixed(png_const_structrp png_ptr, png_inforp info_ptr, png_set_gAMA_fixed(png_const_structrp png_ptr, png_inforp info_ptr,
...@@ -294,7 +341,7 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr, ...@@ -294,7 +341,7 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type, png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type,
int nparams, png_const_charp units, png_charpp params) int nparams, png_const_charp units, png_charpp params)
{ {
png_size_t length; size_t length;
int i; int i;
png_debug1(1, "in %s storage function", "pCAL"); png_debug1(1, "in %s storage function", "pCAL");
...@@ -371,7 +418,7 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr, ...@@ -371,7 +418,7 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
memcpy(info_ptr->pcal_units, units, length); memcpy(info_ptr->pcal_units, units, length);
info_ptr->pcal_params = png_voidcast(png_charpp, png_malloc_warn(png_ptr, info_ptr->pcal_params = png_voidcast(png_charpp, png_malloc_warn(png_ptr,
(png_size_t)(((unsigned int)nparams + 1) * (sizeof (png_charp))))); (size_t)(((unsigned int)nparams + 1) * (sizeof (png_charp)))));
if (info_ptr->pcal_params == NULL) if (info_ptr->pcal_params == NULL)
{ {
...@@ -411,7 +458,7 @@ void PNGAPI ...@@ -411,7 +458,7 @@ void PNGAPI
png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr, png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr,
int unit, png_const_charp swidth, png_const_charp sheight) int unit, png_const_charp swidth, png_const_charp sheight)
{ {
png_size_t lengthw = 0, lengthh = 0; size_t lengthw = 0, lengthh = 0;
png_debug1(1, "in %s storage function", "sCAL"); png_debug1(1, "in %s storage function", "sCAL");
...@@ -672,7 +719,7 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr, ...@@ -672,7 +719,7 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
{ {
png_charp new_iccp_name; png_charp new_iccp_name;
png_bytep new_iccp_profile; png_bytep new_iccp_profile;
png_size_t length; size_t length;
png_debug1(1, "in %s storage function", "iCCP"); png_debug1(1, "in %s storage function", "iCCP");
...@@ -999,7 +1046,7 @@ png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr, ...@@ -999,7 +1046,7 @@ png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr,
/* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */ /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
info_ptr->trans_alpha = png_voidcast(png_bytep, info_ptr->trans_alpha = png_voidcast(png_bytep,
png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH)); png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH));
memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans); memcpy(info_ptr->trans_alpha, trans_alpha, (size_t)num_trans);
} }
png_ptr->trans_alpha = info_ptr->trans_alpha; png_ptr->trans_alpha = info_ptr->trans_alpha;
} }
...@@ -1079,7 +1126,7 @@ png_set_sPLT(png_const_structrp png_ptr, ...@@ -1079,7 +1126,7 @@ png_set_sPLT(png_const_structrp png_ptr,
do do
{ {
png_size_t length; size_t length;
/* Skip invalid input entries */ /* Skip invalid input entries */
if (entries->name == NULL || entries->entries == NULL) if (entries->name == NULL || entries->entries == NULL)
...@@ -1130,8 +1177,9 @@ png_set_sPLT(png_const_structrp png_ptr, ...@@ -1130,8 +1177,9 @@ png_set_sPLT(png_const_structrp png_ptr,
info_ptr->valid |= PNG_INFO_sPLT; info_ptr->valid |= PNG_INFO_sPLT;
++(info_ptr->splt_palettes_num); ++(info_ptr->splt_palettes_num);
++np; ++np;
++entries;
} }
while (++entries, --nentries); while (--nentries);
if (nentries > 0) if (nentries > 0)
png_chunk_report(png_ptr, "sPLT out of memory", PNG_CHUNK_WRITE_ERROR); png_chunk_report(png_ptr, "sPLT out of memory", PNG_CHUNK_WRITE_ERROR);
...@@ -1382,6 +1430,7 @@ png_set_keep_unknown_chunks(png_structrp png_ptr, int keep, ...@@ -1382,6 +1430,7 @@ png_set_keep_unknown_chunks(png_structrp png_ptr, int keep,
static PNG_CONST png_byte chunks_to_ignore[] = { static PNG_CONST png_byte chunks_to_ignore[] = {
98, 75, 71, 68, '\0', /* bKGD */ 98, 75, 71, 68, '\0', /* bKGD */
99, 72, 82, 77, '\0', /* cHRM */ 99, 72, 82, 77, '\0', /* cHRM */
101, 88, 73, 102, '\0', /* eXIf */
103, 65, 77, 65, '\0', /* gAMA */ 103, 65, 77, 65, '\0', /* gAMA */
104, 73, 83, 84, '\0', /* hIST */ 104, 73, 83, 84, '\0', /* hIST */
105, 67, 67, 80, '\0', /* iCCP */ 105, 67, 67, 80, '\0', /* iCCP */
...@@ -1542,7 +1591,7 @@ png_set_rows(png_const_structrp png_ptr, png_inforp info_ptr, ...@@ -1542,7 +1591,7 @@ png_set_rows(png_const_structrp png_ptr, png_inforp info_ptr,
#endif #endif
void PNGAPI void PNGAPI
png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size) png_set_compression_buffer_size(png_structrp png_ptr, size_t size)
{ {
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
...@@ -1724,14 +1773,16 @@ png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key) ...@@ -1724,14 +1773,16 @@ png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key)
png_byte ch = (png_byte)*key++; png_byte ch = (png_byte)*key++;
if ((ch > 32 && ch <= 126) || (ch >= 161 /*&& ch <= 255*/)) if ((ch > 32 && ch <= 126) || (ch >= 161 /*&& ch <= 255*/))
*new_key++ = ch, ++key_len, space = 0; {
*new_key++ = ch; ++key_len; space = 0;
}
else if (space == 0) else if (space == 0)
{ {
/* A space or an invalid character when one wasn't seen immediately /* A space or an invalid character when one wasn't seen immediately
* before; output just a space. * before; output just a space.
*/ */
*new_key++ = 32, ++key_len, space = 1; *new_key++ = 32; ++key_len; space = 1;
/* If the character was not a space then it is invalid. */ /* If the character was not a space then it is invalid. */
if (ch != 32) if (ch != 32)
...@@ -1744,7 +1795,7 @@ png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key) ...@@ -1744,7 +1795,7 @@ png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key)
if (key_len > 0 && space != 0) /* trailing space */ if (key_len > 0 && space != 0) /* trailing space */
{ {
--key_len, --new_key; --key_len; --new_key;
if (bad_character == 0) if (bad_character == 0)
bad_character = 32; bad_character = 32;
} }
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
* However, the following notice accompanied the original version of this * However, the following notice accompanied the original version of this
* file and, per its terms, should not be removed: * file and, per its terms, should not be removed:
* *
* Last changed in libpng 1.6.28 [January 5, 2017] * Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
/* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib /* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib
* can handle at once. This type need be no larger than 16 bits (so maximum of * can handle at once. This type need be no larger than 16 bits (so maximum of
* 65535), this define allows us to discover how big it is, but limited by the * 65535), this define allows us to discover how big it is, but limited by the
* maximuum for png_size_t. The value can be overriden in a library build * maximum for size_t. The value can be overridden in a library build
* (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably * (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably
* lower value (e.g. 255 works). A lower value may help memory usage (slightly) * lower value (e.g. 255 works). A lower value may help memory usage (slightly)
* and may even improve performance on some systems (and degrade it on others.) * and may even improve performance on some systems (and degrade it on others.)
...@@ -242,7 +242,7 @@ struct png_struct_def ...@@ -242,7 +242,7 @@ struct png_struct_def
png_uint_32 height; /* height of image in pixels */ png_uint_32 height; /* height of image in pixels */
png_uint_32 num_rows; /* number of rows in current pass */ png_uint_32 num_rows; /* number of rows in current pass */
png_uint_32 usr_width; /* width of row at start of write */ png_uint_32 usr_width; /* width of row at start of write */
png_size_t rowbytes; /* size of row in bytes */ size_t rowbytes; /* size of row in bytes */
png_uint_32 iwidth; /* width of current interlaced row in pixels */ png_uint_32 iwidth; /* width of current interlaced row in pixels */
png_uint_32 row_number; /* current row in interlace pass */ png_uint_32 row_number; /* current row in interlace pass */
png_uint_32 chunk_name; /* PNG_CHUNK() id of current chunk */ png_uint_32 chunk_name; /* PNG_CHUNK() id of current chunk */
...@@ -260,7 +260,7 @@ struct png_struct_def ...@@ -260,7 +260,7 @@ struct png_struct_def
png_bytep try_row; /* buffer to save trial row when filtering */ png_bytep try_row; /* buffer to save trial row when filtering */
png_bytep tst_row; /* buffer to save best trial row when filtering */ png_bytep tst_row; /* buffer to save best trial row when filtering */
#endif #endif
png_size_t info_rowbytes; /* Added in 1.5.4: cache of updated row bytes */ size_t info_rowbytes; /* Added in 1.5.4: cache of updated row bytes */
png_uint_32 idat_size; /* current IDAT size for read */ png_uint_32 idat_size; /* current IDAT size for read */
png_uint_32 crc; /* current chunk CRC value */ png_uint_32 crc; /* current chunk CRC value */
...@@ -335,7 +335,7 @@ struct png_struct_def ...@@ -335,7 +335,7 @@ struct png_struct_def
#endif #endif
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
png_color_8 shift; /* shift for significant bit tranformation */ png_color_8 shift; /* shift for significant bit transformation */
#endif #endif
#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \ #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
...@@ -356,10 +356,10 @@ struct png_struct_def ...@@ -356,10 +356,10 @@ struct png_struct_def
png_bytep current_buffer; /* buffer for recently used data */ png_bytep current_buffer; /* buffer for recently used data */
png_uint_32 push_length; /* size of current input chunk */ png_uint_32 push_length; /* size of current input chunk */
png_uint_32 skip_length; /* bytes to skip in input data */ png_uint_32 skip_length; /* bytes to skip in input data */
png_size_t save_buffer_size; /* amount of data now in save_buffer */ size_t save_buffer_size; /* amount of data now in save_buffer */
png_size_t save_buffer_max; /* total size of save_buffer */ size_t save_buffer_max; /* total size of save_buffer */
png_size_t buffer_size; /* total amount of available input data */ size_t buffer_size; /* total amount of available input data */
png_size_t current_buffer_size; /* amount of data now in current_buffer */ size_t current_buffer_size; /* amount of data now in current_buffer */
int process_mode; /* what push library is currently doing */ int process_mode; /* what push library is currently doing */
int cur_palette; /* current push library palette index */ int cur_palette; /* current push library palette index */
...@@ -479,7 +479,7 @@ struct png_struct_def ...@@ -479,7 +479,7 @@ struct png_struct_def
#endif #endif
/* New member added in libpng-1.2.26 */ /* New member added in libpng-1.2.26 */
png_size_t old_big_row_buf_size; size_t old_big_row_buf_size;
#ifdef PNG_READ_SUPPORTED #ifdef PNG_READ_SUPPORTED
/* New member added in libpng-1.2.30 */ /* New member added in libpng-1.2.30 */
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
* However, the following notice accompanied the original version of this * However, the following notice accompanied the original version of this
* file and, per its terms, should not be removed: * file and, per its terms, should not be removed:
* *
* Last changed in libpng 1.6.26 [October 20, 2016] * Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
...@@ -297,8 +297,8 @@ png_do_invert(png_row_infop row_info, png_bytep row) ...@@ -297,8 +297,8 @@ png_do_invert(png_row_infop row_info, png_bytep row)
if (row_info->color_type == PNG_COLOR_TYPE_GRAY) if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
{ {
png_bytep rp = row; png_bytep rp = row;
png_size_t i; size_t i;
png_size_t istop = row_info->rowbytes; size_t istop = row_info->rowbytes;
for (i = 0; i < istop; i++) for (i = 0; i < istop; i++)
{ {
...@@ -311,8 +311,8 @@ png_do_invert(png_row_infop row_info, png_bytep row) ...@@ -311,8 +311,8 @@ png_do_invert(png_row_infop row_info, png_bytep row)
row_info->bit_depth == 8) row_info->bit_depth == 8)
{ {
png_bytep rp = row; png_bytep rp = row;
png_size_t i; size_t i;
png_size_t istop = row_info->rowbytes; size_t istop = row_info->rowbytes;
for (i = 0; i < istop; i += 2) for (i = 0; i < istop; i += 2)
{ {
...@@ -326,8 +326,8 @@ png_do_invert(png_row_infop row_info, png_bytep row) ...@@ -326,8 +326,8 @@ png_do_invert(png_row_infop row_info, png_bytep row)
row_info->bit_depth == 16) row_info->bit_depth == 16)
{ {
png_bytep rp = row; png_bytep rp = row;
png_size_t i; size_t i;
png_size_t istop = row_info->rowbytes; size_t istop = row_info->rowbytes;
for (i = 0; i < istop; i += 4) for (i = 0; i < istop; i += 4)
{ {
...@@ -542,11 +542,15 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start) ...@@ -542,11 +542,15 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
if (at_start != 0) /* Skip initial filler */ if (at_start != 0) /* Skip initial filler */
++sp; ++sp;
else /* Skip initial channel and, for sp, the filler */ else /* Skip initial channel and, for sp, the filler */
sp += 2, ++dp; {
sp += 2; ++dp;
}
/* For a 1 pixel wide image there is nothing to do */ /* For a 1 pixel wide image there is nothing to do */
while (sp < ep) while (sp < ep)
*dp++ = *sp, sp += 2; {
*dp++ = *sp; sp += 2;
}
row_info->pixel_depth = 8; row_info->pixel_depth = 8;
} }
...@@ -556,10 +560,14 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start) ...@@ -556,10 +560,14 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
if (at_start != 0) /* Skip initial filler */ if (at_start != 0) /* Skip initial filler */
sp += 2; sp += 2;
else /* Skip initial channel and, for sp, the filler */ else /* Skip initial channel and, for sp, the filler */
sp += 4, dp += 2; {
sp += 4; dp += 2;
}
while (sp < ep) while (sp < ep)
*dp++ = *sp++, *dp++ = *sp, sp += 3; {
*dp++ = *sp++; *dp++ = *sp; sp += 3;
}
row_info->pixel_depth = 16; row_info->pixel_depth = 16;
} }
...@@ -582,11 +590,15 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start) ...@@ -582,11 +590,15 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
if (at_start != 0) /* Skip initial filler */ if (at_start != 0) /* Skip initial filler */
++sp; ++sp;
else /* Skip initial channels and, for sp, the filler */ else /* Skip initial channels and, for sp, the filler */
sp += 4, dp += 3; {
sp += 4; dp += 3;
}
/* Note that the loop adds 3 to dp and 4 to sp each time. */ /* Note that the loop adds 3 to dp and 4 to sp each time. */
while (sp < ep) while (sp < ep)
*dp++ = *sp++, *dp++ = *sp++, *dp++ = *sp, sp += 2; {
*dp++ = *sp++; *dp++ = *sp++; *dp++ = *sp; sp += 2;
}
row_info->pixel_depth = 24; row_info->pixel_depth = 24;
} }
...@@ -596,14 +608,16 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start) ...@@ -596,14 +608,16 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
if (at_start != 0) /* Skip initial filler */ if (at_start != 0) /* Skip initial filler */
sp += 2; sp += 2;
else /* Skip initial channels and, for sp, the filler */ else /* Skip initial channels and, for sp, the filler */
sp += 8, dp += 6; {
sp += 8; dp += 6;
}
while (sp < ep) while (sp < ep)
{ {
/* Copy 6 bytes, skip 2 */ /* Copy 6 bytes, skip 2 */
*dp++ = *sp++, *dp++ = *sp++; *dp++ = *sp++; *dp++ = *sp++;
*dp++ = *sp++, *dp++ = *sp++; *dp++ = *sp++; *dp++ = *sp++;
*dp++ = *sp++, *dp++ = *sp, sp += 3; *dp++ = *sp++; *dp++ = *sp; sp += 3;
} }
row_info->pixel_depth = 48; row_info->pixel_depth = 48;
...@@ -623,7 +637,7 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start) ...@@ -623,7 +637,7 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
return; /* The filler channel has gone already */ return; /* The filler channel has gone already */
/* Fix the rowbytes value. */ /* Fix the rowbytes value. */
row_info->rowbytes = (unsigned int)(dp-row); row_info->rowbytes = (size_t)(dp-row);
} }
#endif #endif
...@@ -722,7 +736,7 @@ png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info) ...@@ -722,7 +736,7 @@ png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info)
* forms produced on either GCC or MSVC. * forms produced on either GCC or MSVC.
*/ */
int padding = PNG_PADBITS(row_info->pixel_depth, row_info->width); int padding = PNG_PADBITS(row_info->pixel_depth, row_info->width);
png_bytep rp = png_ptr->row_buf + row_info->rowbytes; png_bytep rp = png_ptr->row_buf + row_info->rowbytes - 1;
switch (row_info->bit_depth) switch (row_info->bit_depth)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册