Commit b0c3ea2bb6e0cab1d09726f3e66742eaf45c5745
1 parent
ca79fcb2
Refactor test for /Pages object in QPDF::copyForeignObject
Test for missing object before accessing obj_copier.object_map.
Showing
2 changed files
with
7 additions
and
7 deletions
libqpdf/QPDF.cc
| ... | ... | @@ -2034,13 +2034,13 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign) |
| 2034 | 2034 | } |
| 2035 | 2035 | obj_copier.to_copy.clear(); |
| 2036 | 2036 | |
| 2037 | - auto& result = obj_copier.object_map[foreign.getObjGen()]; | |
| 2038 | - if (!result.isInitialized()) { | |
| 2039 | - result = QPDFObjectHandle::newNull(); | |
| 2040 | - warn(damagedPDF("Unexpected reference to /Pages object while copying foreign object. " | |
| 2041 | - "Replacing with Null object.")); | |
| 2037 | + auto og = foreign.getObjGen(); | |
| 2038 | + if (!obj_copier.object_map.count(og)) { | |
| 2039 | + warn(damagedPDF("unexpected reference to /Pages object while copying foreign object; " | |
| 2040 | + "replacing with null")); | |
| 2041 | + return QPDFObjectHandle::newNull(); | |
| 2042 | 2042 | } |
| 2043 | - return result; | |
| 2043 | + return obj_copier.object_map[foreign.getObjGen()]; | |
| 2044 | 2044 | } |
| 2045 | 2045 | |
| 2046 | 2046 | void | ... | ... |
qpdf/qtest/qpdf/copy-foreign-objects-25.out
| 1 | -WARNING: minimal.pdf (object 6 0, offset 556): Unexpected reference to /Pages object while copying foreign object. Replacing with Null object. | |
| 1 | +WARNING: minimal.pdf (object 6 0, offset 556): unexpected reference to /Pages object while copying foreign object; replacing with null | |
| 2 | 2 | test 25 done | ... | ... |