2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 10:58:58 +00:00

Add new methods Xref_table::subsections

Calculate all subsections before reading subsection entries.

Duplicates some warnings for the time being.
This commit is contained in:
m-holger 2024-08-14 13:48:35 +01:00
parent cee8d5c92d
commit ed65619428
3 changed files with 36 additions and 5 deletions

View File

@ -829,6 +829,34 @@ QPDF::Xref_table::subsection(std::string const& line)
file->getLastOffset() + toI(p - start)};
}
std::vector<QPDF::Xref_table::Subsection>
QPDF::Xref_table::subsections(std::string& line)
{
std::vector<QPDF::Xref_table::Subsection> result;
qpdf_offset_t f1 = 0;
int f2 = 0;
char type = '\0';
while (true) {
line.assign(50, '\0');
file->read(line.data(), line.size());
auto [obj, num, offset] = result.emplace_back(subsection(line));
file->seek(offset, SEEK_SET);
for (qpdf_offset_t i = obj; i - num < obj; ++i) {
if (!read_entry(f1, f2, type)) {
QTC::TC("qpdf", "QPDF invalid xref entry");
throw damaged_table("invalid xref entry (obj=" + std::to_string(i) + ")");
}
}
qpdf_offset_t pos = file->tell();
if (read_token().isWord("trailer")) {
return result;
} else {
file->seek(pos, SEEK_SET);
}
}
}
bool
QPDF::Xref_table::read_bad_entry(qpdf_offset_t& f1, int& f2, char& type)
{
@ -970,10 +998,8 @@ QPDF::Xref_table::read_table(qpdf_offset_t xref_offset)
{
file->seek(xref_offset, SEEK_SET);
std::string line;
while (true) {
line.assign(50, '\0');
file->read(line.data(), line.size());
auto [obj, num, offset] = subsection(line);
auto subs = subsections(line);
for (auto [obj, num, offset]: subs) {
file->seek(offset, SEEK_SET);
for (qpdf_offset_t i = obj; i - num < obj; ++i) {
if (i == 0) {
@ -985,7 +1011,6 @@ QPDF::Xref_table::read_table(qpdf_offset_t xref_offset)
int f2 = 0;
char type = '\0';
if (!read_entry(f1, f2, type)) {
QTC::TC("qpdf", "QPDF invalid xref entry");
throw damaged_table("invalid xref entry (obj=" + std::to_string(i) + ")");
}
if (type == 'f') {

View File

@ -125,6 +125,7 @@ class QPDF::Xref_table
// Methods to parse tables
qpdf_offset_t read_table(qpdf_offset_t offset);
std::vector<Subsection> subsections(std::string& line);
Subsection subsection(std::string const& line);
bool read_entry(qpdf_offset_t& f1, int& f2, char& type);
bool read_bad_entry(qpdf_offset_t& f1, int& f2, char& type);

View File

@ -3,6 +3,11 @@ WARNING: xref-errors.pdf (xref table, offset 606): accepting invalid xref table
WARNING: xref-errors.pdf (xref table, offset 627): accepting invalid xref table entry
WARNING: xref-errors.pdf (xref table, offset 648): accepting invalid xref table entry
WARNING: xref-errors.pdf (xref table, offset 667): accepting invalid xref table entry
WARNING: xref-errors.pdf (xref table, offset 585): accepting invalid xref table entry
WARNING: xref-errors.pdf (xref table, offset 606): accepting invalid xref table entry
WARNING: xref-errors.pdf (xref table, offset 627): accepting invalid xref table entry
WARNING: xref-errors.pdf (xref table, offset 648): accepting invalid xref table entry
WARNING: xref-errors.pdf (xref table, offset 667): accepting invalid xref table entry
checking xref-errors.pdf
PDF Version: 1.3
File is not encrypted