1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Merge pull request #18047 from Snuffleupagus/issue-18042

Avoid re-parsing global images that failed decoding (issue 18042, PR 17428 follow-up)
This commit is contained in:
Tim van der Meij 2024-05-15 15:40:18 +02:00 committed by GitHub
commit 4db843617f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 109 additions and 23 deletions

View file

@ -55,6 +55,7 @@
!issue17679.pdf
!issue17679_2.pdf
!issue18030.pdf
!issue18042.pdf
!issue14953.pdf
!issue15367.pdf
!issue15372.pdf

BIN
test/pdfs/issue18042.pdf Normal file

Binary file not shown.

View file

@ -4203,6 +4203,65 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
firstStatsOverall = null;
});
it("caches image resources at the document/page level, with corrupt images (issue 18042)", async function () {
const { NUM_PAGES_THRESHOLD } = GlobalImageCache;
const loadingTask = getDocument(buildGetDocumentParams("issue18042.pdf"));
const pdfDoc = await loadingTask.promise;
let checkedGlobalDecodeFailed = false;
for (let i = 1; i <= pdfDoc.numPages; i++) {
const pdfPage = await pdfDoc.getPage(i);
const viewport = pdfPage.getViewport({ scale: 1 });
const canvasAndCtx = CanvasFactory.create(
viewport.width,
viewport.height
);
const renderTask = pdfPage.render({
canvasContext: canvasAndCtx.context,
viewport,
});
await renderTask.promise;
const opList = renderTask.getOperatorList();
// The canvas is no longer necessary, since we only care about
// the image-data below.
CanvasFactory.destroy(canvasAndCtx);
const { commonObjs, objs } = pdfPage;
const imgIndex = opList.fnArray.indexOf(OPS.paintImageXObject);
const [objId] = opList.argsArray[imgIndex];
if (i < NUM_PAGES_THRESHOLD) {
expect(objId).toEqual(`img_p${i - 1}_1`);
expect(objs.has(objId)).toEqual(true);
expect(commonObjs.has(objId)).toEqual(false);
} else {
expect(objId).toEqual(
`g_${loadingTask.docId}_img_p${NUM_PAGES_THRESHOLD - 1}_1`
);
expect(objs.has(objId)).toEqual(false);
expect(commonObjs.has(objId)).toEqual(true);
}
// Ensure that the actual image data is identical for all pages.
const objsPool = i >= NUM_PAGES_THRESHOLD ? commonObjs : objs;
const imgData = objsPool.get(objId);
expect(imgData).toBe(null);
if (i === NUM_PAGES_THRESHOLD) {
checkedGlobalDecodeFailed = true;
}
}
expect(checkedGlobalDecodeFailed).toBeTruthy();
await loadingTask.destroy();
});
it("render for printing, with `printAnnotationStorage` set", async function () {
async function getPrintData(printAnnotationStorage = null) {
const canvasAndCtx = CanvasFactory.create(