diff --git a/src/core/jpeg_stream.js b/src/core/jpeg_stream.js index 068f75e6e..c4cb56920 100644 --- a/src/core/jpeg_stream.js +++ b/src/core/jpeg_stream.js @@ -134,6 +134,17 @@ const JpegStream = (function JpegStreamClosure() { stream.pos += 2; // Skip marker length. stream.pos += 1; // Skip precision. const scanLines = stream.getUint16(); + const samplesPerLine = stream.getUint16(); + + // Letting the browser handle the JPEG decoding, on the main-thread, + // will cause a *large* increase in peak memory usage since there's + // a handful of short-lived copies of the image data. For very big + // JPEG images, always let the PDF.js image decoder handle them to + // reduce overall memory usage during decoding (see issue 11694). + if (scanLines * samplesPerLine > 1e6) { + validDimensions = false; + break; + } // The "normal" case, where the image data and dictionary agrees. if (scanLines === dictHeight) {