Compare commits

...

10 Commits

Author SHA1 Message Date
Peter Kasting
d675c669c8 Fix an instance of -Wunused-but-set-variable.
See https://github.com/glennrp/libpng/pull/388
2022-03-20 15:58:34 +01:00
Vadim Zeitlin
dc6985f9d2 Avoid bogus -Wmaybe-uninitialized from gcc 11
It doesn't really matter that number_buf is not initialized because its
first characters are not going to be used anyhow (png_format_number()
returns a pointer to the actually used part of the string at the end),
but gcc-11 warns about it, so do initialize it just to make it happy.
2022-03-09 20:09:17 +01:00
Vadim Zeitlin
9853c67ab4 Merge branch 'apple-cond-use-inflate-validate' of https://github.com/discnl/libpng into wx
Fix check for availability of zlib's inflateValidate() under Apple
systems.

See https://github.com/wxWidgets/libpng/pull/5
2020-12-30 17:44:40 +01:00
Dimitri Schoolwerth
b825c1723d
Try to use inflateValidate in case of static zlib
When static linking zlib on iOS/macOS the usage of inflateValidate is
still unnecessarily based on OS version checks. Detect at least the case
where zlib functions are definitions (as a result of compiling zlib with
a prefix), allowing for unrestricted inflateValidate usage.
2020-12-17 17:01:20 +01:00
Dimitri Schoolwerth
e69f6b3e26
Add iOS/macOS run-time check for inflateValidate 2020-12-17 02:22:25 +01:00
Dimitri Schoolwerth
fd4a538c67
Add iOS compile-time check for inflateValidate
Don't use inflateValidate if targeting pre-iOS 11.
2020-12-17 02:16:30 +01:00
Dimitri Schoolwerth
759dc457a8
Fix continued undesired usage of inflateValidate
Macro MAC_OS_X_VERSION_MIN_REQUIRED isn't present through, coincidental,
inclusion of <Availability.h>, which means inflateValidate can still be
used resulting in a warning when targeting pre-10.13 and a crash if
called pre-10.13 as described in (attempted fix) bda2970c65.

Fix by including the needed header explicitly.
2020-12-17 01:49:19 +01:00
Dimitri Schoolwerth
dfc331f0bd
Refactor check for zlib's inflateValidate presence
No compile-time changes. Refactor a single and expanding statement
checking for availability of inflateValidate into an option.
2020-12-16 17:09:22 +01:00
maccy2
3ffeff7877 Fix: 'inflateValidate' is only available on macOS 10.13 or newer
The warning occurs when compiling the latest wxWidgets 3.1.1 on macOS
and will cause the final application code to crash if run on macOS <
10.13. The patch fixes the issue, following this one:
8d2a287da3/external/libpng/libpng-osx.patch.1

See https://github.com/wxWidgets/libpng/pull/1
2020-07-21 22:29:54 +02:00
Vadim Zeitlin
46b17e804b Avoid -Wundef for MIPS and PPC symbols too
This is similar to d532334ef (Avoid -Wundef warnings when building
libpng, 2017-11-13), but for the similar symbols used under the other
architectures: always define them, even if just as 0, to avoid gcc
warnings when comparing them with 0 later.
2020-05-02 20:29:26 +02:00
4 changed files with 66 additions and 8 deletions

2
png.c
View File

@ -752,7 +752,7 @@ png_convert_to_rfc1123_buffer(char out[29], png_const_timep ptime)
{
size_t pos = 0;
char number_buf[5]; /* enough for a four-digit year */
char number_buf[5] = {0}; /* enough for a four-digit year */
# define APPEND_STRING(string) pos = png_safecat(out, 29, pos, (string))
# define APPEND_NUMBER(format, value)\

View File

@ -268,11 +268,15 @@
# ifndef PNG_MIPS_MSA_IMPLEMENTATION
# define PNG_MIPS_MSA_IMPLEMENTATION 1
# endif
#else
# define PNG_MIPS_MSA_IMPLEMENTATION 0
#endif /* PNG_MIPS_MSA_OPT > 0 */
#if PNG_POWERPC_VSX_OPT > 0
# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_vsx
# define PNG_POWERPC_VSX_IMPLEMENTATION 1
#else
# define PNG_POWERPC_VSX_IMPLEMENTATION 0
#endif

View File

@ -3452,7 +3452,6 @@ png_image_read_background(png_voidp argument)
for (pass = 0; pass < passes; ++pass)
{
png_bytep row = png_voidcast(png_bytep, display->first_row);
unsigned int startx, stepx, stepy;
png_uint_32 y;
@ -3557,8 +3556,6 @@ png_image_read_background(png_voidp argument)
inrow += 2; /* gray and alpha channel */
}
row += display->row_bytes;
}
}
}

View File

@ -18,6 +18,61 @@
#ifdef PNG_READ_SUPPORTED
#ifndef PNG_USE_ZLIB_INFLATE_VALIDATE
/* Check if zlib's inflateValidate can be used. */
# if ZLIB_VERNUM >= 0x1290 && \
defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_IGNORE_ADLER32)
# if defined(__APPLE__) && defined(__MACH__)
/* Determine whether inflateValidate is available by checking:
* - for static zlib linking (best, but flaky and unreliable detection)
* - at run-time by OS version (best with sys zlib usage)
* - at compile-time by minimal supported OS version
*/
/* For TARGET_OS_IPHONE / TARGET_OS_MAC */
# include <TargetConditionals.h>
/* For IPHONE_OS_VERSION_MIN_REQUIRED / MAC_OS_X_VERSION_MIN_REQUIRED.
* Not using the preferred <Availability.h> because it was introduced
* during the 10.5 SDK while this header has been available with Xcode
* since 1.0 (10.3 SDK).
*/
# include <AvailabilityMacros.h>
# ifdef inflateValidate
/* Without this (empty) check usage of inflateValidate is driven
* only by OS version while zlib with inflateValidate could be
* linked statically.
* If the system's zlib is being used inflateValidate is not a
* macro so by checking if inflateValidate is a macro the cases
* where zlib is compiled with a prefix are at least handled and
* inflateValidate can then be used regardless of OS version.
*/
# elif defined(__clang__) && __has_builtin(__builtin_available)
/* Check at run-time for availability by OS version. */
# define PNG_USE_ZLIB_INFLATE_VALIDATE 2
# elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
# if defined(IPHONE_OS_VERSION_MIN_REQUIRED) && \
IPHONE_OS_VERSION_MIN_REQUIRED < 110000
/* Don't use if targeting pre-iOS 11.0. */
# define PNG_USE_ZLIB_INFLATE_VALIDATE 0
# endif
# elif defined(TARGET_OS_MAC) && TARGET_OS_MAC
# if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \
MAC_OS_X_VERSION_MIN_REQUIRED < 101300
/* Don't use if targeting pre-macOS 10.13. */
# define PNG_USE_ZLIB_INFLATE_VALIDATE 0
# endif
# endif /* inflateValidate */
# endif /* __APPLE__ && __MACH__ */
# else
# define PNG_USE_ZLIB_INFLATE_VALIDATE 0
# endif /* ZLIB_VERNUM && PNG_SET_OPTION_SUPPORTED && PNG_IGNORE_ADLER32 */
# ifndef PNG_USE_ZLIB_INFLATE_VALIDATE
# define PNG_USE_ZLIB_INFLATE_VALIDATE 1
# endif
#endif /* PNG_USE_ZLIB_INFLATE_VALIDATE */
png_uint_32 PNGAPI
png_get_uint_31(png_const_structrp png_ptr, png_const_bytep buf)
{
@ -422,11 +477,13 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED;
}
#if ZLIB_VERNUM >= 0x1290 && \
defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_IGNORE_ADLER32)
#if PNG_USE_ZLIB_INFLATE_VALIDATE
if (((png_ptr->options >> PNG_IGNORE_ADLER32) & 3) == PNG_OPTION_ON)
/* Turn off validation of the ADLER32 checksum in IDAT chunks */
ret = inflateValidate(&png_ptr->zstream, 0);
# if PNG_USE_ZLIB_INFLATE_VALIDATE == 2
if (__builtin_available(macOS 10.13, iOS 11.0, *))
# endif
/* Turn off validation of the ADLER32 checksum in IDAT chunks */
ret = inflateValidate(&png_ptr->zstream, 0);
#endif
if (ret == Z_OK)