Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/core/editor/pdf_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ class PDFEditor {
obj = obj.slice();
}
for (let i = 0, ii = obj.length; i < ii; i++) {
const postponedActions = postponedRefCopies.get(obj[i]);
const postponedActions =
obj[i] instanceof Ref && postponedRefCopies.get(obj[i]);
if (postponedActions) {
// The object is a reference that needs to be copied later.
postponedActions.push(ref => (obj[i] = ref));
Expand Down Expand Up @@ -277,7 +278,8 @@ class PDFEditor {
}
if (dict) {
for (const [key, rawObj] of dict.getRawEntries()) {
const postponedActions = postponedRefCopies.get(rawObj);
const postponedActions =
rawObj instanceof Ref && postponedRefCopies.get(rawObj);
if (postponedActions) {
// The object is a reference that needs to be copied later.
postponedActions.push(ref => dict.set(key, ref));
Expand Down Expand Up @@ -1083,7 +1085,7 @@ class PDFEditor {

// Fix the ID tree.
for (const [id, nodeRef] of idTree || []) {
const newNodeRef = oldRefMapping.get(nodeRef);
const newNodeRef = nodeRef instanceof Ref && oldRefMapping.get(nodeRef);
const newId = dedupIDs.get(id) || id;
if (newNodeRef) {
newIdTree.set(newId, newNodeRef);
Expand Down Expand Up @@ -1137,7 +1139,7 @@ class PDFEditor {
const newDestinations = (documentData.destinations = new Map());
for (const [key, dest] of Object.entries(destinations)) {
const pageRef = dest[0];
const pageData = pagesMap.get(pageRef);
const pageData = pageRef instanceof Ref && pagesMap.get(pageRef);
if (!pageData) {
continue;
}
Expand Down Expand Up @@ -1537,7 +1539,7 @@ class PDFEditor {
}
const { oldRefMapping } = documentData;
for (const coRef of co) {
const newCoRef = oldRefMapping.get(coRef);
const newCoRef = coRef instanceof Ref && oldRefMapping.get(coRef);
if (newCoRef) {
calculationOrder.push(newCoRef);
}
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -888,3 +888,4 @@
!outlines_for_editor.pdf
!mesh_shading_empty.pdf
!acroform_calculation_order.pdf
!extractPages_null_in_array.pdf
Binary file added test/pdfs/extractPages_null_in_array.pdf
Binary file not shown.
16 changes: 16 additions & 0 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6763,5 +6763,21 @@ small scripts as well as for`);
await newLoadingTask.destroy();
});
});

describe("extract pages with null values in arrays", function () {
it("should not crash when a page resource contains an array with null entries", async function () {
const loadingTask = getDocument(
buildGetDocumentParams("extractPages_null_in_array.pdf")
);
const pdfDoc = await loadingTask.promise;
const data = await pdfDoc.extractPages([{ document: null }]);
await loadingTask.destroy();

const newLoadingTask = getDocument(data);
const newPdfDoc = await newLoadingTask.promise;
expect(newPdfDoc.numPages).toEqual(1);
await newLoadingTask.destroy();
});
});
});
});
Loading