Bug 1530222 - Allow libpng to allocate larger chunks for decoding purposes. r=tnikkel
authorAndrew Osmond <aosmond@mozilla.com>
Thu, 28 Feb 2019 08:44:43 -0500
changeset 462088 6b78699bdf7ba05ed68892140dec7ba175ba95d9
parent 462087 339a3c5969e1ccea01a68a0c61373cffd7436022
child 462089 e41148de8adf5c5e19859d215c19280769bc8c19
push id35635
push userrmaries@mozilla.com
push dateSat, 02 Mar 2019 09:41:56 +0000
treeherdermozilla-central@82134a2f7b89 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstnikkel
bugs1530222
milestone67.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 1530222 - Allow libpng to allocate larger chunks for decoding purposes. r=tnikkel Differential Revision: https://phabricator.services.mozilla.com/D21533
image/decoders/nsPNGDecoder.cpp
--- a/image/decoders/nsPNGDecoder.cpp
+++ b/image/decoders/nsPNGDecoder.cpp
@@ -39,16 +39,20 @@ static LazyLogModule sPNGDecoderAccounti
 // limit image dimensions (bug #251381, #591822, #967656, and #1283961)
 #ifndef MOZ_PNG_MAX_WIDTH
 #  define MOZ_PNG_MAX_WIDTH 0x7fffffff  // Unlimited
 #endif
 #ifndef MOZ_PNG_MAX_HEIGHT
 #  define MOZ_PNG_MAX_HEIGHT 0x7fffffff  // Unlimited
 #endif
 
+/* Controls the maximum chunk size configuration for libpng. We set this to a
+ * very large number, 256MB specifically. */
+static constexpr png_alloc_size_t kPngMaxChunkSize = 0x10000000;
+
 nsPNGDecoder::AnimFrameInfo::AnimFrameInfo()
     : mDispose(DisposalMethod::KEEP), mBlend(BlendMethod::OVER), mTimeout(0) {}
 
 #ifdef PNG_APNG_SUPPORTED
 
 int32_t GetNextFrameDelay(png_structp aPNG, png_infop aInfo) {
   // Delay, in seconds, is delayNum / delayDen.
   png_uint_16 delayNum = png_get_next_frame_delay_num(aPNG, aInfo);
@@ -307,19 +311,17 @@ nsresult nsPNGDecoder::InitInternal() {
   }
 
   png_set_keep_unknown_chunks(mPNG, 1, unused_chunks,
                               (int)sizeof(unused_chunks) / 5);
 #endif
 
 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
   png_set_user_limits(mPNG, MOZ_PNG_MAX_WIDTH, MOZ_PNG_MAX_HEIGHT);
-  if (mCMSMode != eCMSMode_Off) {
-    png_set_chunk_malloc_max(mPNG, 4000000L);
-  }
+  png_set_chunk_malloc_max(mPNG, kPngMaxChunkSize);
 #endif
 
 #ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
   // 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.