2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-14 08:44:04 +00:00

Merge pull request #1269 from m-holger/hybrid

Fix handling of hybrid reference files in QPDF::read_xrefTable
This commit is contained in:
m-holger 2024-09-17 09:50:59 +01:00 committed by GitHub
commit bcf56e5333
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -952,8 +952,6 @@ QPDF::read_xrefEntry(qpdf_offset_t& f1, int& f2, char& type)
qpdf_offset_t
QPDF::read_xrefTable(qpdf_offset_t xref_offset)
{
std::vector<QPDFObjGen> deleted_items;
m->file->seek(xref_offset, SEEK_SET);
std::string line;
while (true) {
@ -982,8 +980,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset)
"xref table", "invalid xref entry (obj=" + std::to_string(i) + ")");
}
if (type == 'f') {
// Save deleted items until after we've checked the XRefStm, if any.
deleted_items.emplace_back(toI(i), f2);
insertFreeXrefEntry(QPDFObjGen(toI(i), f2));
} else {
insertXrefEntry(toI(i), 1, f1, f2);
}
@ -1030,23 +1027,16 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset)
}
}
// Handle any deleted items now that we've read the /XRefStm.
for (auto const& og: deleted_items) {
insertFreeXrefEntry(og);
}
if (cur_trailer.hasKey("/Prev")) {
if (!cur_trailer.getKey("/Prev").isInteger()) {
QTC::TC("qpdf", "QPDF trailer prev not integer");
throw damagedPDF("trailer", "/Prev key in trailer dictionary is not an integer");
}
QTC::TC("qpdf", "QPDF prev key in trailer dictionary");
xref_offset = cur_trailer.getKey("/Prev").getIntValue();
} else {
xref_offset = 0;
return cur_trailer.getKey("/Prev").getIntValue();
}
return xref_offset;
return 0;
}
// Read a single cross-reference stream.