Commit 2b4dcb33aa3cc130241894df78e2b67bbe5c99b8
Committed by
GitHub
Merge pull request #1014 from m-holger/i1011
Change QPDF::copyForeignObject to return a null object when called wi…
Showing
3 changed files
with
11 additions
and
6 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
qpdf/test_driver.cc
| ... | ... | @@ -954,6 +954,8 @@ test_25(QPDF& pdf, char const* arg2) |
| 954 | 954 | // Copy qtest without crossing page boundaries. Should get O1 |
| 955 | 955 | // and O2 and their streams but not O3 or any other pages. |
| 956 | 956 | |
| 957 | + // Also verify that attempts to copy /Pages objects return null. | |
| 958 | + | |
| 957 | 959 | assert(arg2 != nullptr); |
| 958 | 960 | { |
| 959 | 961 | // Make sure original PDF is out of scope when we write. |
| ... | ... | @@ -961,6 +963,8 @@ test_25(QPDF& pdf, char const* arg2) |
| 961 | 963 | oldpdf.processFile(arg2); |
| 962 | 964 | QPDFObjectHandle qtest = oldpdf.getTrailer().getKey("/QTest"); |
| 963 | 965 | pdf.getTrailer().replaceKey("/QTest", pdf.copyForeignObject(qtest)); |
| 966 | + | |
| 967 | + assert(pdf.copyForeignObject(oldpdf.getRoot().getKey("/Pages")).isNull()); | |
| 964 | 968 | } |
| 965 | 969 | |
| 966 | 970 | QPDFWriter w(pdf, "a.pdf"); | ... | ... |