Bug 1277397 - High memory usage triggered by a jpg
If an image's size is larger than the SurfaceCache maximum
capacity limit, load it sequentially rather than progressivly.
MozReview-Commit-ID: Eskyw6Xk812
--- a/image/decoders/nsJPEGDecoder.cpp
+++ b/image/decoders/nsJPEGDecoder.cpp
@@ -373,32 +373,29 @@ nsJPEGDecoder::ReadJPEGData(const char*
default:
mState = JPEG_ERROR;
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
("} (unknown colorpsace (3))"));
return Transition::TerminateFailure();
}
}
+ //If the memory needed by the image is bigger than the SurfaceCache size limit,
+ //Decode sequentially and don't make this a buffered image.
+ if ( ((mInfo.image_width * mInfo.image_height) *24) >
+ SurfaceCache::MaximumCapacity())
+ {
+ mDecodeStyle = SEQUENTIAL;
+ }
+
// Don't allocate a giant and superfluous memory buffer
// when not doing a progressive decode.
mInfo.buffered_image = mDecodeStyle == PROGRESSIVE &&
jpeg_has_multiple_scans(&mInfo);
- //If the memory needed by the image is bigger than the SurfaceCache size limit,
- // & we're a buffered image, don't start decompressing. Bail out.
- if ( mInfo.buffered_image && ((mInfo.image_width * mInfo.image_height) *24) >
- SurfaceCache::MaximumCapacity()) {
- mState= JPEG_ERROR;
- MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
- ("} (Image size is larger than SurfaceCache::MaximumCapacity"));
- return Transition::TerminateFailure();
- }
-
-
/* Used to set up image size so arrays can be allocated */
jpeg_calc_output_dimensions(&mInfo);
MOZ_ASSERT(!mImageData, "Already have a buffer allocated?");
nsresult rv = AllocateFrame(/* aFrameNum = */ 0, OutputSize(),
FullOutputFrame(), SurfaceFormat::B8G8R8X8);
if (NS_FAILED(rv)) {
mState = JPEG_ERROR;
--- a/image/decoders/nsJPEGDecoder.h
+++ b/image/decoders/nsJPEGDecoder.h
@@ -102,17 +102,17 @@ public:
JOCTET * mProfile;
uint32_t mProfileLength;
qcms_profile* mInProfile;
qcms_transform* mTransform;
bool mReading;
- const Decoder::DecodeStyle mDecodeStyle;
+ Decoder::DecodeStyle mDecodeStyle;
uint32_t mCMSMode;
};
} // namespace image
} // namespace mozilla
#endif // mozilla_image_decoders_nsJPEGDecoder_h