Commit d64b14912d2f96e81fc56c15b19c9678bd5e58f6
1 parent
3ddc51a9
Move QPDF::readTrailer to QPDF::Xref_table
Showing
3 changed files
with
11 additions
and
10 deletions
include/qpdf/QPDF.hh
| ... | ... | @@ -760,7 +760,6 @@ class QPDF |
| 760 | 760 | void parse(char const* password); |
| 761 | 761 | void inParse(bool); |
| 762 | 762 | void setLastObjectDescription(std::string const& description, QPDFObjGen const& og); |
| 763 | - QPDFObjectHandle readTrailer(); | |
| 764 | 763 | QPDFObjectHandle readObject(std::string const& description, QPDFObjGen og); |
| 765 | 764 | void readStream(QPDFObjectHandle& object, QPDFObjGen og, qpdf_offset_t offset); |
| 766 | 765 | void validateStreamLineEnd(QPDFObjectHandle& object, QPDFObjGen og, qpdf_offset_t offset); | ... | ... |
libqpdf/QPDF.cc
| ... | ... | @@ -596,7 +596,7 @@ QPDF::Xref_table::reconstruct(QPDFExc& e) |
| 596 | 596 | file->seek(pos, SEEK_SET); |
| 597 | 597 | } else if (!trailer && t1.isWord("trailer")) { |
| 598 | 598 | auto pos = file->tell(); |
| 599 | - QPDFObjectHandle t = qpdf.readTrailer(); | |
| 599 | + QPDFObjectHandle t = read_trailer(); | |
| 600 | 600 | if (!t.isDictionary()) { |
| 601 | 601 | // Oh well. It was worth a try. |
| 602 | 602 | } else { |
| ... | ... | @@ -994,7 +994,7 @@ QPDF::Xref_table::read_table(qpdf_offset_t xref_offset) |
| 994 | 994 | } |
| 995 | 995 | |
| 996 | 996 | // Set offset to previous xref table if any |
| 997 | - auto cur_trailer = qpdf.readTrailer(); | |
| 997 | + auto cur_trailer = read_trailer(); | |
| 998 | 998 | if (!cur_trailer.isDictionary()) { |
| 999 | 999 | QTC::TC("qpdf", "QPDF missing trailer"); |
| 1000 | 1000 | throw qpdf.damagedPDF("", "expected trailer dictionary"); |
| ... | ... | @@ -1456,21 +1456,21 @@ QPDF::setLastObjectDescription(std::string const& description, QPDFObjGen const& |
| 1456 | 1456 | } |
| 1457 | 1457 | |
| 1458 | 1458 | QPDFObjectHandle |
| 1459 | -QPDF::readTrailer() | |
| 1459 | +QPDF::Xref_table::read_trailer() | |
| 1460 | 1460 | { |
| 1461 | - qpdf_offset_t offset = m->file->tell(); | |
| 1461 | + qpdf_offset_t offset = file->tell(); | |
| 1462 | 1462 | bool empty = false; |
| 1463 | 1463 | auto object = |
| 1464 | - QPDFParser(*m->file, "trailer", m->tokenizer, nullptr, this, true).parse(empty, false); | |
| 1464 | + QPDFParser(*qpdf.m->file, "trailer", *tokenizer, nullptr, &qpdf, true).parse(empty, false); | |
| 1465 | 1465 | if (empty) { |
| 1466 | 1466 | // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in |
| 1467 | 1467 | // actual PDF files and Adobe Reader appears to ignore them. |
| 1468 | - warn(damagedPDF("trailer", "empty object treated as null")); | |
| 1469 | - } else if (object.isDictionary() && readToken(*m->file).isWord("stream")) { | |
| 1470 | - warn(damagedPDF("trailer", m->file->tell(), "stream keyword found in trailer")); | |
| 1468 | + qpdf.warn(qpdf.damagedPDF("trailer", "empty object treated as null")); | |
| 1469 | + } else if (object.isDictionary() && read_token().isWord("stream")) { | |
| 1470 | + qpdf.warn(qpdf.damagedPDF("trailer", file->tell(), "stream keyword found in trailer")); | |
| 1471 | 1471 | } |
| 1472 | 1472 | // Override last_offset so that it points to the beginning of the object we just read |
| 1473 | - m->file->setLastOffset(offset); | |
| 1473 | + file->setLastOffset(offset); | |
| 1474 | 1474 | return object; |
| 1475 | 1475 | } |
| 1476 | 1476 | ... | ... |
libqpdf/qpdf/QPDF_private.hh
| ... | ... | @@ -54,6 +54,8 @@ class QPDF::Xref_table: public std::map<QPDFObjGen, QPDFXRefEntry> |
| 54 | 54 | int max_num_entries, |
| 55 | 55 | std::function<QPDFExc(std::string_view)> damaged); |
| 56 | 56 | |
| 57 | + QPDFObjectHandle read_trailer(); | |
| 58 | + | |
| 57 | 59 | QPDFTokenizer::Token |
| 58 | 60 | read_token(size_t max_len = 0) |
| 59 | 61 | { | ... | ... |