From cc6ef1f3b1a8f9141ffaca41b904c13acf22ca97 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 10 May 2023 22:50:22 +0200 Subject: [PATCH] No issue - Limit JPEG decoder memory allocation to surface cache size. This means that for trivial images whose header specifies large dimensions but with no image data, we don't waste a lot of memory. See BZ bug 1277397 --- image/decoders/nsJPEGDecoder.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/image/decoders/nsJPEGDecoder.cpp b/image/decoders/nsJPEGDecoder.cpp index 7fc749890f..1ac25fc6e2 100644 --- a/image/decoders/nsJPEGDecoder.cpp +++ b/image/decoders/nsJPEGDecoder.cpp @@ -154,6 +154,10 @@ nsJPEGDecoder::InitInternal() mSourceMgr.skip_input_data = skip_input_data; mSourceMgr.resync_to_restart = jpeg_resync_to_restart; mSourceMgr.term_source = term_source; + + // Limit the maximum allocation to the maximum our surface cache can hold. + mInfo.mem->max_memory_to_use = static_cast( + std::min(SurfaceCache::MaximumCapacity(), LONG_MAX)); // Record app markers for ICC data for (uint32_t m = 0; m < 16; m++) {