diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 41081c5f4..ec363c73d 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -546,6 +546,12 @@ class PartialEvaluator { } _sendImgData(objId, imgData, cacheGlobally = false) { + if ( + (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) && + imgData + ) { + assert(Number.isInteger(imgData.dataLen), "Expected dataLen to be set."); + } const transfers = imgData ? [imgData.bitmap || imgData.data.buffer] : null; if (this.parsingType3Font || cacheGlobally) { @@ -690,6 +696,10 @@ class PartialEvaluator { const objId = `mask_${this.idFactory.createObjId()}`; operatorList.addDependency(objId); + + imgData.dataLen = imgData.bitmap + ? imgData.width * imgData.height * 4 + : imgData.data.length; this._sendImgData(objId, imgData); args = [ @@ -790,12 +800,12 @@ class PartialEvaluator { /* isOffscreenCanvasSupported = */ this.options .isOffscreenCanvasSupported ); + imgData.dataLen = imgData.bitmap + ? imgData.width * imgData.height * 4 + : imgData.data.length; if (cacheKey && imageRef && cacheGlobally) { - const length = imgData.bitmap - ? imgData.width * imgData.height * 4 - : imgData.data.length; - this.globalImageCache.addByteSize(imageRef, length); + this.globalImageCache.addByteSize(imageRef, imgData.dataLen); } return this._sendImgData(objId, imgData, cacheGlobally); diff --git a/src/display/api.js b/src/display/api.js index cd332473f..d77830e58 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -2781,18 +2781,8 @@ class WorkerTransport { pageProxy.objs.resolve(id, imageData); // Heuristic that will allow us not to store large data. - if (imageData) { - let length; - if (imageData.bitmap) { - const { width, height } = imageData; - length = width * height * 4; - } else { - length = imageData.data?.length || 0; - } - - if (length > MAX_IMAGE_SIZE_TO_CACHE) { - pageProxy._maybeCleanupAfterRender = true; - } + if (imageData?.dataLen > MAX_IMAGE_SIZE_TO_CACHE) { + pageProxy._maybeCleanupAfterRender = true; } break; case "Pattern":