509 Commits

Author SHA1 Message Date
John Bowler
3d024874a5 Recently introduced palette sharing bug
The internal read code change to stop sharing the palette was incompletely
implemented.  The result is that unless palette index checking is turned off and
there are no read transformations the png_info palette gets deleted when the
png_struct is deleted.  This is normally harmless (png_info gets deleted first)
but in the case of pngcp it results in use-after-free of the palette and,
therefore, palette corruption and maybe on some operating systems and access
violation.

This also updated pngcp 'search' mode to check a restricted range of memLevels;
there is an unrelated bug which means that lower zlib memLevels result in memory
corruption under some circumstances, probably less often than 1:1000.

Signed-off-by: John Bowler <jbowler@acm.org>
2016-01-12 09:36:10 -08:00
Glenn Randers-Pehrson
89ebb4dd52 [libpng17] Happy 2016! Updated copyright year 2016-01-02 13:51:52 -06:00
Glenn Randers-Pehrson
15b6717221 [libpng17] Update copyright years in source files. 2015-12-13 22:37:27 -06:00
John Bowler
84a8bb8244 Make png_struct palette, trans_alpha private
This removes the side-effect on the png_struct palette of calling png_set_PLTE
or png_set_tRNS.  NOTE: this is a quiet API change, it was possible before to
alter the palette on a PNG image by using png_set_PLTE, but this was unintended
and inconsistent with the other png_set APIs.

Fix a bug in palette index checking; png_struct::num_palette could, in
principle, get changed by the transformations (e.g. png_set_quantize) and this
would invalidate the check.  The palette checking init function now makes a copy
of png_struct::num_palette.

Fix a bug in pngvalid error handling.  A png_error in png_write_info is not
continuable (a valid image cannot necessarily be written afterward) because the
png_error aborts the write of subsequent pre-IDAT chunks.  In particular an
abort as a result of a bogus colorspace information (gAMA, cHRM, sBIT etc)
prevents the write of the PLTE chunk.

Signed-off-by: John Bowler <jbowler@acm.org>
2015-12-01 08:16:53 -08:00
Glenn Randers-Pehrson
5db709d83c [libpng17] Updated CHANGES and ANNOUNCE, removed trailing blanks from *.c *.h 2015-11-24 14:38:52 -06:00
John Bowler
23324b8559 sBIT code coverage and fixes
Fixes for sBIT handling in the low-bit-depth gray and pngstest cases, extends
sBIT handling to the colormap code in the simplified API which is separately
implemented in pngread.c

Signed-off-by: John Bowler <jbowler@acm.org>
2015-09-26 15:24:20 -07:00
Glenn Randers-Pehrson
c23bdb1445 [libpng17] #ifdef out some dead code in pngrtran.c when sBIT is disabled. 2015-09-25 22:33:41 -05:00
John Bowler
53e537439f Fix png_set_tRNS_to_alpha for low-bit-depth gray
Signed-off-by: John Bowler <jbowler@acm.org>
2015-09-25 16:22:17 -07:00
John Bowler
d394d889e1 png_rgb_to_gray optimization fixes
This fixes the code that optimizes RGB to Gray transformations that only
selected on channel and clarifies the handling of max_depth in the transform
code.  It eliminates some UNTESTED cases and removes the write 'invert alpha'
UNTESTED macro because, while there are no test cases for it, code review
some months after writing it suggests it is ok.

Signed-off-by: John Bowler <jbowler@acm.org>
2015-09-24 17:33:32 -07:00
John Bowler
8c025bcf3f Simplified API sRGB gamma handling correction
If a gamma encoded file that has a gamma not matching that of sRGB is passed to
the simplified API the previous code simply interpreted it as a power law
encoding.  However old Mac files had a power law correction of 1.45 built in to
the encoding, even though the display devices were consistent with sRGB.
Assuming a power law encoding results in substantial differences in the
interpretation of low 8-bit values; below 10.  For example an Apple '5' which is
equivalent to an sRGB '17' ends up as the value '8'.

This patch provides some measure of correction for this by making the gamma
correction done within the simplified API assume that any encoded data is
encoded relative to an sRGB-like transfer function; the data is corrected back
to the PNG-nominal 2.2 value then decoded to linear (if required) using the sRGB
transfer function.

This reduces the errors reported by pngstest for such files (colormapped ones)
but still leaves the issue with files where the standard libpng code does the
gamma decoding.  To cope with the latter cases the patch also includes a new
pngstest-errors which allows the result, however this is still a
work-in-progress; a better solution is possible.

Signed-off-by: John Bowler <jbowler@acm.org>
2015-09-20 20:40:52 -07:00
John Bowler
493bfd14a2 gamma handling fixes
One serious bug; 8 was forced as a bit depth when caching a palette, even though
the palette have been expanded.  One less serious bug, the optimization for
avoiding gamma correction introduced significant errors if the app subsequently
did further corrections, only shown by using gAMA 1/1.52 files in pngstest.

Signed-off-by: John Bowler <jbowler@acm.org>
2015-09-19 16:36:22 -07:00
John Bowler
38647d4b21 [libpng17] Fixed makepng.c so that it compiles with GCC 5.1.0.
Added contrib/testspngs/: a directory for additional test png files
2015-09-18 16:36:57 -05:00
John Bowler
f8d3e854cb Coverity related changes
These should fix most of the reported Coverity issues.  The remaining issues
should be the back_b etc assignments, which look like a Coverity bug, and
passing a pointer to a byte to a function that expects a pointer to one or more
bytes, which should (I believe) be fixed in one case and not the other
(next_filter) case; the latter case will probably go away as I am going to
rewrite that piece of code to avoid a spurious buffer allocation.

Signed-off-by: John Bowler <jbowler@acm.org>
2015-09-17 22:04:30 -05:00
John Bowler
fea86b1c29 Remove memcpy of png_transform_background
Replaced by a structure copy which is safer since it doesn't depend on knowing
the first member to be copied, also the copies are improved to copy the
transform args too; not required at present but it may prevent a bug being
introduced in the future.

Signed-off-by: John Bowler <jbowler@acm.org>
2015-09-16 21:33:43 -07:00
John Bowler
601ae5387e [libpng17] correct low-depth-gray code and enable tests
The low-bit-depth gray tests were disabled in prior versions of libpng because
of problems which should have been fixed by the recent changes to libpng17,
enabling the tests reveals bugs in those changes which are fixed by this commit.

Signed-off-by: John Bowler <jbowler@acm.org>
2015-09-16 21:09:10 -07:00
John Bowler
3184947a25 chunk handling and transform rewrite
This implements a new chunk parse implementation that can be shared, it
is currently shared by the progressive reader and the sequential one
(not, yet, the writer).

The patch also implements shared transform handling that is used
throughout.

Signed-off-by: John Bowler <jbowler@acm.org>
2015-09-14 20:42:40 -07:00
John Bowler
1a9eb510eb [libpng17] Moved READ_GAMMA to pngrtran.c. This makes everything in pngrtrans.c
depend on READ_TRANSFORMS and moves all the transform gamma (READ_GAMMA)
code from elsewhere to png_tran.c.  There are no code changes.
There is one remaining use of the gamma (16-bit) code in the simplified
API in pngread.c but that is because of a long-standing libpng bug,
namely that the gamma corrected palette is no produced by
png_read_update_info (John Bowler).
2015-06-04 21:49:54 -05:00
John Bowler
673ae608ab [libpng17] Transformed rewrite: changed row_info, added checks. This introduces an
internal struct (png_transform_control) to replace row_info and uses
    that to implement affirms correctly.  The change also adds checks on
    the rowbytes calculation and additional checks on most transform
    implementations.
Added png_uint_16 range checking, pngvalid tRNS, fixed png_uint_16:
    review of previous checks, removal of some where SAFE. pngvalid: add
    testing of tRNS for better code coverage pngvalid: correct rgb-to-gray
    error calculations. Code coverage is still incomplete: see /*UNTESTED*/
    in pngrtran.c
2015-03-30 21:32:41 -05:00
John Bowler
53097f5bbb [libpng17] Check (png_uint_16) casts for overflow. Also removed png_muldiv_warn,
added RELEASE/!RELEASE convenience macros. png_muldiv_warn was used in
only one place, and the overflow condition is a genuine warning not
an internal error.  Four macros allow code or function parameters to be
condition on RELEASE (or not) builds and tidy up the #ifdef handling of
functions.
2015-03-22 20:26:13 -05:00
John Bowler
82fa6aed0e [libpng17] Added byte, short and other overflow checking
Added 'assert' based overflow checking for debug builds for char
and short assignments. Simply ignore the error in release builds
(a truncated value will be used without warning). Controlled by
PNG_RANGE_CHECK_SUPPORTED.
2015-03-22 15:57:53 -05:00
Glenn Randers-Pehrson
06963c7841 [libpng16] Renamed "assert" to "affirm", not affected by NDEBUG. 2015-03-21 21:33:42 -05:00
John Bowler
2460d9494d [libpng17] Implemented assert support and usage. 2015-03-20 16:39:56 -05:00
Glenn Randers-Pehrson
c2f0c9683f [libpng17] Work in progress, merging with libpng-1.6.17rc01. 2015-03-04 14:24:54 -06:00
Glenn Randers-Pehrson
6ce2d220b4 [lipng17] Do not build png_product2() when it is unused and work around
one more Coverity-scan dead-code warning.
2015-02-07 08:54:07 -06:00
Glenn Randers-Pehrson
3043819fb2 [libpng17] Quieted some Coverity warnings 2015-01-27 15:54:37 -06:00
Glenn Randers-Pehrson
b1d49de5bc [libpng17] Happy New Year -- update copyright year. 2014-12-31 18:43:44 -06:00
John Bowler
d7e9c1c584 [libpng17] Fixed byte order in 2-byte filler, in png_do_read_filler(). 2014-12-29 16:06:32 -06:00
Glenn Randers-Pehrson
ab71e135e7 [libpng17] Imported from libpng-1.7.0beta42.tar 2014-11-20 10:23:06 -06:00
Glenn Randers-Pehrson
aeb4a22975 [libpng17] Changed "#endif /* PNG_FEATURE_SUPPORTED */" to "#endif /* FEATURE */" 2014-11-06 23:09:14 -06:00
Glenn Randers-Pehrson
9c0b5ab848 [libpng17] Removed #ifdef PNG_16BIT_SUPPORTED/#endif around png_product2(); it is
needed by png_reciprocal2().
Added #ifdef PNG_16BIT_SUPPORTED/#endif around png_log16bit() and
    png_do_swap().
2014-11-06 21:14:16 -06:00
Glenn Randers-Pehrson
7a4bfbdec1 [libpng17] Ported cosmetic changes from libpng-1.6.15beta02. 2014-11-01 13:57:38 -05:00
Glenn Randers-Pehrson
4e61b58980 [libpng17] Use "if (value != 0)" instead of "if (value)" consistently. 2014-03-08 13:25:55 -06:00
John Bowler
dc63b03da1 [libpng17] Completed full working pngimage test program and added two test
scripts.  Fixed combination of ~alpha with shift. On read invert alpha,
processing occurred after shift processing, which causes the final values to be
outside the range that should be produced by the shift. Reversing the
order on read makes the two transforms work together correctly and mirrors
the order used on write.
2014-02-05 11:39:59 -06:00
Glenn Randers-Pehrson
28711dff2a [libpng17] Updated copyright year in recently-changed files. 2013-12-31 21:15:11 -06:00
Glenn Randers-Pehrson
a2c5f56e77 [libpng17] Imported from libpng-1.7.0beta25.tar 2013-12-26 11:53:02 -06:00
Glenn Randers-Pehrson
1faa6ff32c [libpng17] Handle zero-length PLTE chunk or NULL palette with png_error()
instead of png_chunk_report(), which by default issues a warning
rather than an error, leading to later reading from a NULL pointer
(png_ptr->palette) in png_do_expand_palette().
2013-12-15 08:47:52 -06:00
John Bowler
3adf438f39 [libpng17] Made transform implementation functions static. This makes the
internal functions called by png_do_{read|write}_transformations static.
On an x86-64 DLL build (Gentoo Linux) this reduces the size of the text
segment of the DLL by 1208 bytes, about 0.6%. It also simplifies
maintenance by removing the declarations from pngpriv.h and allowing
easier changes to the internal interfaces.
2013-12-13 23:55:41 -06:00
John Bowler
d45a632529 [libpng17] Bookkeeping: Moved functions around (no changes). Moved transform
function definitions before the place where they are called so that
they can be masde static. Move the intrapixel functions and the
grayscale palette builder out of the png?tran.c files. The latter
isn't a transform function and is no longer used internally, and the
former MNG specific functions are better placed in pngread/pngwrite.c
2013-12-13 23:50:30 -06:00
Glenn Randers-Pehrson
003590c361 [libpng17] Imported from libpng-1.7.0beta17.tar 2013-08-21 19:13:18 -05:00
Glenn Randers-Pehrson
79fc8fa0d9 [libpng17] Exit loop over tRNS array once a transparent pixel is found
(performance report by PoChun Chang).
2013-08-04 14:05:39 -05:00
Glenn Randers-Pehrson
6cf97e37af [libpng17] Bump version to 1.7.0beta08 2013-04-18 07:39:57 -05:00
John Bowler
066f9862f0 [libpng17] Corrected the test on user transform changes on read. It was in the
png_set of the transform function, but that doesn't matter unless the
transform function changes the rowbuf size, and that is only valid if
transform_info is called.
2013-04-12 22:10:38 -05:00
Glenn Randers-Pehrson
851a6265a8 [libpng17] Use parentheses consistently with #if defined()
and wrapped some long lines.
2013-02-17 15:25:29 -06:00
Glenn Randers-Pehrson
ab097b1168 [libpng17] Updated copyright year to 2013 in changed files. 2013-01-01 08:54:06 -06:00
John Bowler
46369f35c5 [libpng17] Fixed Windows build issues, enabled ARM compilation. Various warnings issued
by earlier versions of GCC fixed for Cygwin and Min/GW (which both use old GCCs.)
ARM support is enabled by default in zlib.props (unsupported by Microsoft) and
ARM compilation is made possible by deleting the check for x86. The test programs
cannot be run because they are not signed.
2012-12-20 22:58:13 -06:00
John Bowler
fbbbc620b8 [libpng16] Fixed previous support for Z_PREFIX in configure builds, corrected
sCAL APIs; some of these use floating point arithmetic so they need to be
disabled if floating point arithmetic is switched off.  This is a quiet API
change - previously it appeared that the APIs were supported if fixed point
arithmetic was used internally, however they required certain APIs (floor,
modf, frexp, atof) that are part of C floating point support. Changed
png_fixed and the gamma code specific version of the same to avoid floor(),
which may be a library function (not an intrinsic). Removed unused #if 0
code.
2012-12-17 21:07:30 -06:00
John Bowler
d59c19b64c [libpng17] Removed more functions that were deprecated in libpng-1.6.0:
png_malloc_default png_free_default.
  Updated some left over "1.6.0beta32" in code sources.
  Fixed a "png_structp" prototype (should be png_structrp) in arm_init.c
  Updated the version-number hack in pngvalid.c
2012-12-15 21:41:31 -06:00
Glenn Randers-Pehrson
bbabd977d1 [libpng17] Fixed some typos in comments; updated manual. 2012-12-15 17:12:48 -06:00
John Bowler
240ac287eb [libpng17]Rearranged png_struct, remove unused members, change png_set_filter
handling png_struct members rearranged - partly to reorder to avoid packing,
partly to put frequently accessed members at the start and partly to make
the grouping more clear. png_set_filter code has been rewritten and the
code shared with png_write_start_row moved to a common function.  Comments
in png.h have been made more clear. Minor fixes to
contrib/libtests/timepng.c and some of the png_*_tRNS logic, including
more error detection in png_set_tRNS.
2012-12-14 22:31:50 -06:00
John Bowler
3e42c81193 [libpng17] Made 8-bit compose and rgb_to_grayscale accuracy improvements.
These changes cause 16-bit arithmetic to be used for 8-bit data in the gamma
    corrected compose and grayscale operations.  The arithmetic errors have
    three sources all of which are fixed in this commit:
    1) 8-bit linear calculations produce massive errors for lower intensity
       values.
    2) The old 16-bit "16 to 8" gamma table code erroneously wrote the lowest
       output value into a table entry which corresponded to multiple output
       values (so where the value written should have been the closest to the
       transformed input value.)
    3) In a number of cases the code to access the 16-bit table did not round;
       it did a simple shift, which was wrong and made the side effects of (2)
       even worse.
  The new gamma code does not have the 16-to-8 problem at the cost of slighly
    more calculations and the algorithm used to minimize the number of
    calculations has been extended to all the 16-bit tables; it has advantages
    for any significant gamma correction.
2012-12-14 22:17:54 -06:00