Skip to content

Commit

Permalink
Merge pull request #11707 from Snuffleupagus/issue-11694
Browse files Browse the repository at this point in the history
Always prefer the PDF.js JPEG decoder for very large images, in order to reduce peak memory usage (issue 11694)
  • Loading branch information
timvandermeij authored Mar 24, 2020
2 parents f851053 + 62a9c26 commit 292b77f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/core/jpeg_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 292b77f

Please sign in to comment.