Bug 1315863 - Use PNG_MAXIMUM_INFLATE_WINDOW to ensure maximum compatibility with existing images. r=glennrp
authorAndrew Osmond <aosmond@mozilla.com>
Wed, 16 Nov 2016 15:21:33 -0500
changeset 322931 39806168b32d986e60b30da981b87501140c447f
parent 322930 0a8aa6175b4ccb1869e738e1f551d0a267e1cfe2
child 322932 17757ba4c0e82c7300a0b832b1726230cbbe5f29
push id30964
push usercbook@mozilla.com
push dateThu, 17 Nov 2016 13:34:58 +0000
treeherdermozilla-central@41fe2fa4ddab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglennrp
bugs1315863
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1315863 - Use PNG_MAXIMUM_INFLATE_WINDOW to ensure maximum compatibility with existing images. r=glennrp
image/decoders/nsPNGDecoder.cpp
media/libpng/pnglibconf.h
--- a/image/decoders/nsPNGDecoder.cpp
+++ b/image/decoders/nsPNGDecoder.cpp
@@ -335,22 +335,30 @@ nsPNGDecoder::InitInternal()
   // Disallow palette-index checking, for speed; we would ignore the warning
   // anyhow.  This feature was added at libpng version 1.5.10 and is disabled
   // in the embedded libpng but enabled by default in the system libpng.  This
   // call also disables it in the system libpng, for decoding speed.
   // Bug #745202.
   png_set_check_for_invalid_index(mPNG, 0);
 #endif
 
-#if defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_sRGB_PROFILE_CHECKS) && \
-            PNG_sRGB_PROFILE_CHECKS >= 0
+#ifdef PNG_SET_OPTION_SUPPORTED
+#if defined(PNG_sRGB_PROFILE_CHECKS) && PNG_sRGB_PROFILE_CHECKS >= 0
   // Skip checking of sRGB ICC profiles
   png_set_option(mPNG, PNG_SKIP_sRGB_CHECK_PROFILE, PNG_OPTION_ON);
 #endif
 
+#ifdef PNG_MAXIMUM_INFLATE_WINDOW
+  // Force a larger zlib inflate window as some images in the wild have
+  // incorrectly set metadata (specifically CMF bits) which prevent us from
+  // decoding them otherwise.
+  png_set_option(mPNG, PNG_MAXIMUM_INFLATE_WINDOW, PNG_OPTION_ON);
+#endif
+#endif
+
   // use this as libpng "progressive pointer" (retrieve in callbacks)
   png_set_progressive_read_fn(mPNG, static_cast<png_voidp>(this),
                               nsPNGDecoder::info_callback,
                               nsPNGDecoder::row_callback,
                               nsPNGDecoder::end_callback);
 
   return NS_OK;
 }
--- a/media/libpng/pnglibconf.h
+++ b/media/libpng/pnglibconf.h
@@ -20,16 +20,17 @@
 #define PNG_GAMMA_THRESHOLD_FIXED 5000
 #define PNG_IDAT_READ_SIZE PNG_ZBUF_SIZE
 #define PNG_INFLATE_BUF_SIZE 1024
 #define PNG_LINKAGE_API extern
 #define PNG_LINKAGE_CALLBACK extern
 #define PNG_LINKAGE_DATA extern
 #define PNG_LINKAGE_FUNCTION extern
 #define PNG_MAX_GAMMA_8 11
+#define PNG_SET_OPTION_SUPPORTED
 #define PNG_sRGB_PROFILE_CHECKS -1
 #define PNG_USER_CHUNK_CACHE_MAX 128
 #define PNG_USER_CHUNK_MALLOC_MAX 4000000L
 #define PNG_USER_HEIGHT_MAX MOZ_PNG_MAX_WIDTH
 #define PNG_USER_WIDTH_MAX MOZ_PNG_MAX_HEIGHT
 #define PNG_WEIGHT_SHIFT 8
 #define PNG_ZBUF_SIZE 8192
 #define PNG_Z_DEFAULT_COMPRESSION (-1)