Commit ac32dbc313db9490165271d1fa2a602315ddb7e0
1 parent
ad73bbcd
Reserve foreign /Page objects in QPDF::copyForeignObject
Ensure that links to foreign pages are not broken provided that the page is subsequently copied.
Showing
3 changed files
with
355 additions
and
355 deletions
libqpdf/QPDF.cc
| @@ -2056,11 +2056,6 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top) | @@ -2056,11 +2056,6 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top) | ||
| 2056 | return; | 2056 | return; |
| 2057 | } | 2057 | } |
| 2058 | 2058 | ||
| 2059 | - if ((!top) && foreign.isPageObject()) { | ||
| 2060 | - QTC::TC("qpdf", "QPDF not crossing page boundary"); | ||
| 2061 | - return; | ||
| 2062 | - } | ||
| 2063 | - | ||
| 2064 | if (foreign.isIndirect()) { | 2059 | if (foreign.isIndirect()) { |
| 2065 | QPDFObjGen foreign_og(foreign.getObjGen()); | 2060 | QPDFObjGen foreign_og(foreign.getObjGen()); |
| 2066 | if (obj_copier.object_map.count(foreign_og) > 0) { | 2061 | if (obj_copier.object_map.count(foreign_og) > 0) { |
| @@ -2075,9 +2070,14 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top) | @@ -2075,9 +2070,14 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top) | ||
| 2075 | } | 2070 | } |
| 2076 | QTC::TC("qpdf", "QPDF copy indirect"); | 2071 | QTC::TC("qpdf", "QPDF copy indirect"); |
| 2077 | if (obj_copier.object_map.count(foreign_og) == 0) { | 2072 | if (obj_copier.object_map.count(foreign_og) == 0) { |
| 2078 | - obj_copier.to_copy.push_back(foreign); | ||
| 2079 | obj_copier.object_map[foreign_og] = | 2073 | obj_copier.object_map[foreign_og] = |
| 2080 | foreign.isStream() ? newStream() : newIndirectNull(); | 2074 | foreign.isStream() ? newStream() : newIndirectNull(); |
| 2075 | + if ((!top) && foreign.isPageObject()) { | ||
| 2076 | + QTC::TC("qpdf", "QPDF not crossing page boundary"); | ||
| 2077 | + obj_copier.visiting.erase(foreign); | ||
| 2078 | + return; | ||
| 2079 | + } | ||
| 2080 | + obj_copier.to_copy.push_back(foreign); | ||
| 2081 | } | 2081 | } |
| 2082 | } | 2082 | } |
| 2083 | 2083 | ||
| @@ -2109,7 +2109,7 @@ QPDF::replaceForeignIndirectObjects(QPDFObjectHandle foreign, ObjCopier& obj_cop | @@ -2109,7 +2109,7 @@ QPDF::replaceForeignIndirectObjects(QPDFObjectHandle foreign, ObjCopier& obj_cop | ||
| 2109 | QTC::TC("qpdf", "QPDF replace indirect"); | 2109 | QTC::TC("qpdf", "QPDF replace indirect"); |
| 2110 | auto mapping = obj_copier.object_map.find(foreign.getObjGen()); | 2110 | auto mapping = obj_copier.object_map.find(foreign.getObjGen()); |
| 2111 | if (mapping == obj_copier.object_map.end()) { | 2111 | if (mapping == obj_copier.object_map.end()) { |
| 2112 | - // This case would occur if this is a reference to a Page or Pages object that we didn't | 2112 | + // This case would occur if this is a reference to a Pages object that we didn't |
| 2113 | // traverse into. | 2113 | // traverse into. |
| 2114 | QTC::TC("qpdf", "QPDF replace foreign indirect with null"); | 2114 | QTC::TC("qpdf", "QPDF replace foreign indirect with null"); |
| 2115 | result = QPDFObjectHandle::newNull(); | 2115 | result = QPDFObjectHandle::newNull(); |
qpdf/qtest/qpdf/test80b1.pdf
No preview for this file type
qpdf/qtest/qpdf/test80b2.pdf
No preview for this file type