From b825c1723ddfdf9f9dae132997f09af1433a65e7 Mon Sep 17 00:00:00 2001 From: Dimitri Schoolwerth Date: Thu, 17 Dec 2020 17:01:20 +0100 Subject: [PATCH] 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. --- pngrutil.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pngrutil.c b/pngrutil.c index 8024ab84a..01ade8863 100644 --- a/pngrutil.c +++ b/pngrutil.c @@ -24,6 +24,7 @@ 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 */ @@ -37,7 +38,16 @@ * since 1.0 (10.3 SDK). */ # include -# if defined(__clang__) && __has_builtin(__builtin_available) +# 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 @@ -52,7 +62,7 @@ /* Don't use if targeting pre-macOS 10.13. */ # define PNG_USE_ZLIB_INFLATE_VALIDATE 0 # endif -# endif +# endif /* inflateValidate */ # endif /* __APPLE__ && __MACH__ */ # else # define PNG_USE_ZLIB_INFLATE_VALIDATE 0