2
1
mirror of https://github.com/qpdf/qpdf.git synced 2025-01-02 22:50:20 +00:00

Merge pull request #1014 from m-holger/i1011

Change QPDF::copyForeignObject to return a null object when called wi…
This commit is contained in:
Jay Berkenbilt 2023-09-03 08:54:12 -04:00 committed by GitHub
commit 2b4dcb33aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 6 deletions

View File

@ -2034,13 +2034,13 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign)
}
obj_copier.to_copy.clear();
auto& result = obj_copier.object_map[foreign.getObjGen()];
if (!result.isInitialized()) {
result = QPDFObjectHandle::newNull();
warn(damagedPDF("Unexpected reference to /Pages object while copying foreign object. "
"Replacing with Null object."));
auto og = foreign.getObjGen();
if (!obj_copier.object_map.count(og)) {
warn(damagedPDF("unexpected reference to /Pages object while copying foreign object; "
"replacing with null"));
return QPDFObjectHandle::newNull();
}
return result;
return obj_copier.object_map[foreign.getObjGen()];
}
void

View File

@ -1 +1,2 @@
WARNING: minimal.pdf (object 6 0, offset 556): unexpected reference to /Pages object while copying foreign object; replacing with null
test 25 done

View File

@ -954,6 +954,8 @@ test_25(QPDF& pdf, char const* arg2)
// Copy qtest without crossing page boundaries. Should get O1
// and O2 and their streams but not O3 or any other pages.
// Also verify that attempts to copy /Pages objects return null.
assert(arg2 != nullptr);
{
// Make sure original PDF is out of scope when we write.
@ -961,6 +963,8 @@ test_25(QPDF& pdf, char const* arg2)
oldpdf.processFile(arg2);
QPDFObjectHandle qtest = oldpdf.getTrailer().getKey("/QTest");
pdf.getTrailer().replaceKey("/QTest", pdf.copyForeignObject(qtest));
assert(pdf.copyForeignObject(oldpdf.getRoot().getKey("/Pages")).isNull());
}
QPDFWriter w(pdf, "a.pdf");