Commit 5d25aac6c7c0363be213124211b7c93eee9c1630

Authored by m-holger
1 parent 258343fc

In QPDFParser constructor change input parameter to InputSource&

libqpdf/QPDF.cc
@@ -1465,7 +1465,7 @@ QPDF::readTrailer() @@ -1465,7 +1465,7 @@ QPDF::readTrailer()
1465 qpdf_offset_t offset = m->file->tell(); 1465 qpdf_offset_t offset = m->file->tell();
1466 bool empty = false; 1466 bool empty = false;
1467 auto object = 1467 auto object =
1468 - QPDFParser(m->file, "trailer", m->tokenizer, nullptr, this, true).parse(empty, false); 1468 + QPDFParser(*m->file, "trailer", m->tokenizer, nullptr, this, true).parse(empty, false);
1469 if (empty) { 1469 if (empty) {
1470 // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in 1470 // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in
1471 // actual PDF files and Adobe Reader appears to ignore them. 1471 // actual PDF files and Adobe Reader appears to ignore them.
@@ -1488,7 +1488,7 @@ QPDF::readObject(std::string const& description, QPDFObjGen og) @@ -1488,7 +1488,7 @@ QPDF::readObject(std::string const& description, QPDFObjGen og)
1488 StringDecrypter decrypter{this, og}; 1488 StringDecrypter decrypter{this, og};
1489 StringDecrypter* decrypter_ptr = m->encp->encrypted ? &decrypter : nullptr; 1489 StringDecrypter* decrypter_ptr = m->encp->encrypted ? &decrypter : nullptr;
1490 auto object = 1490 auto object =
1491 - QPDFParser(m->file, m->last_object_description, m->tokenizer, decrypter_ptr, this, true) 1491 + QPDFParser(*m->file, m->last_object_description, m->tokenizer, decrypter_ptr, this, true)
1492 .parse(empty, false); 1492 .parse(empty, false);
1493 if (empty) { 1493 if (empty) {
1494 // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in 1494 // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in
@@ -1608,7 +1608,7 @@ QPDF::readObjectInStream(std::shared_ptr<InputSource>& input, int obj) @@ -1608,7 +1608,7 @@ QPDF::readObjectInStream(std::shared_ptr<InputSource>& input, int obj)
1608 m->last_object_description += " 0"; 1608 m->last_object_description += " 0";
1609 1609
1610 bool empty = false; 1610 bool empty = false;
1611 - auto object = QPDFParser(input, m->last_object_description, m->tokenizer, nullptr, this, true) 1611 + auto object = QPDFParser(*input, m->last_object_description, m->tokenizer, nullptr, this, true)
1612 .parse(empty, false); 1612 .parse(empty, false);
1613 if (empty) { 1613 if (empty) {
1614 // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in 1614 // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in
libqpdf/QPDFObjectHandle.cc
@@ -2164,7 +2164,7 @@ QPDFObjectHandle::parseContentStream_data( @@ -2164,7 +2164,7 @@ QPDFObjectHandle::parseContentStream_data(
2164 qpdf_offset_t offset = input->getLastOffset(); 2164 qpdf_offset_t offset = input->getLastOffset();
2165 input->seek(offset, SEEK_SET); 2165 input->seek(offset, SEEK_SET);
2166 auto obj = 2166 auto obj =
2167 - QPDFParser(input, "content", tokenizer, nullptr, context, false).parse(empty, true); 2167 + QPDFParser(*input, "content", tokenizer, nullptr, context, false).parse(empty, true);
2168 if (!obj.isInitialized()) { 2168 if (!obj.isInitialized()) {
2169 // EOF 2169 // EOF
2170 break; 2170 break;
@@ -2223,7 +2223,7 @@ QPDFObjectHandle::parse( @@ -2223,7 +2223,7 @@ QPDFObjectHandle::parse(
2223 StringDecrypter* decrypter, 2223 StringDecrypter* decrypter,
2224 QPDF* context) 2224 QPDF* context)
2225 { 2225 {
2226 - return QPDFParser(input, object_description, tokenizer, decrypter, context, false) 2226 + return QPDFParser(*input, object_description, tokenizer, decrypter, context, false)
2227 .parse(empty, false); 2227 .parse(empty, false);
2228 } 2228 }
2229 2229
libqpdf/QPDFParser.cc
@@ -33,9 +33,9 @@ QPDFParser::parse(bool& empty, bool content_stream) @@ -33,9 +33,9 @@ QPDFParser::parse(bool& empty, bool content_stream)
33 33
34 QPDF::ParseGuard pg(context); 34 QPDF::ParseGuard pg(context);
35 empty = false; 35 empty = false;
36 - start = input->tell(); 36 + start = input.tell();
37 37
38 - if (!tokenizer.nextToken(*input, object_description)) { 38 + if (!tokenizer.nextToken(input, object_description)) {
39 warn(tokenizer.getErrorMessage()); 39 warn(tokenizer.getErrorMessage());
40 } 40 }
41 41
@@ -101,7 +101,7 @@ QPDFParser::parse(bool& empty, bool content_stream) @@ -101,7 +101,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
101 } else if (value == "endobj") { 101 } else if (value == "endobj") {
102 // We just saw endobj without having read anything. Treat this as a null and do 102 // We just saw endobj without having read anything. Treat this as a null and do
103 // not move the input source's offset. 103 // not move the input source's offset.
104 - input->seek(input->getLastOffset(), SEEK_SET); 104 + input.seek(input.getLastOffset(), SEEK_SET);
105 empty = true; 105 empty = true;
106 return {QPDF_Null::create()}; 106 return {QPDF_Null::create()};
107 } else { 107 } else {
@@ -138,7 +138,7 @@ QPDFParser::parseRemainder(bool content_stream) @@ -138,7 +138,7 @@ QPDFParser::parseRemainder(bool content_stream)
138 bool b_contents = false; 138 bool b_contents = false;
139 139
140 while (true) { 140 while (true) {
141 - if (!tokenizer.nextToken(*input, object_description)) { 141 + if (!tokenizer.nextToken(input, object_description)) {
142 warn(tokenizer.getErrorMessage()); 142 warn(tokenizer.getErrorMessage());
143 } 143 }
144 ++good_count; // optimistically 144 ++good_count; // optimistically
@@ -151,7 +151,7 @@ QPDFParser::parseRemainder(bool content_stream) @@ -151,7 +151,7 @@ QPDFParser::parseRemainder(bool content_stream)
151 // Process the oldest buffered integer. 151 // Process the oldest buffered integer.
152 addInt(int_count); 152 addInt(int_count);
153 } 153 }
154 - last_offset_buffer[int_count % 2] = input->getLastOffset(); 154 + last_offset_buffer[int_count % 2] = input.getLastOffset();
155 int_buffer[int_count % 2] = QUtil::string_to_ll(tokenizer.getValue().c_str()); 155 int_buffer[int_count % 2] = QUtil::string_to_ll(tokenizer.getValue().c_str());
156 continue; 156 continue;
157 157
@@ -309,7 +309,7 @@ QPDFParser::parseRemainder(bool content_stream) @@ -309,7 +309,7 @@ QPDFParser::parseRemainder(bool content_stream)
309 case QPDFTokenizer::tt_integer: 309 case QPDFTokenizer::tt_integer:
310 if (!content_stream) { 310 if (!content_stream) {
311 // Buffer token in case it is part of an indirect reference. 311 // Buffer token in case it is part of an indirect reference.
312 - last_offset_buffer[1] = input->getLastOffset(); 312 + last_offset_buffer[1] = input.getLastOffset();
313 int_buffer[1] = QUtil::string_to_ll(tokenizer.getValue().c_str()); 313 int_buffer[1] = QUtil::string_to_ll(tokenizer.getValue().c_str());
314 int_count = 1; 314 int_count = 1;
315 } else { 315 } else {
@@ -351,7 +351,7 @@ QPDFParser::parseRemainder(bool content_stream) @@ -351,7 +351,7 @@ QPDFParser::parseRemainder(bool content_stream)
351 if (decrypter) { 351 if (decrypter) {
352 if (b_contents) { 352 if (b_contents) {
353 frame->contents_string = val; 353 frame->contents_string = val;
354 - frame->contents_offset = input->getLastOffset(); 354 + frame->contents_offset = input.getLastOffset();
355 b_contents = false; 355 b_contents = false;
356 } 356 }
357 std::string s{val}; 357 std::string s{val};
@@ -419,7 +419,7 @@ void @@ -419,7 +419,7 @@ void
419 QPDFParser::addScalar(Args&&... args) 419 QPDFParser::addScalar(Args&&... args)
420 { 420 {
421 auto obj = T::create(args...); 421 auto obj = T::create(args...);
422 - obj->setDescription(context, description, input->getLastOffset()); 422 + obj->setDescription(context, description, input.getLastOffset());
423 add(std::move(obj)); 423 add(std::move(obj));
424 } 424 }
425 425
@@ -506,11 +506,11 @@ QPDFParser::warnDuplicateKey() @@ -506,11 +506,11 @@ QPDFParser::warnDuplicateKey()
506 void 506 void
507 QPDFParser::warn(qpdf_offset_t offset, std::string const& msg) const 507 QPDFParser::warn(qpdf_offset_t offset, std::string const& msg) const
508 { 508 {
509 - warn(QPDFExc(qpdf_e_damaged_pdf, input->getName(), object_description, offset, msg)); 509 + warn(QPDFExc(qpdf_e_damaged_pdf, input.getName(), object_description, offset, msg));
510 } 510 }
511 511
512 void 512 void
513 QPDFParser::warn(std::string const& msg) const 513 QPDFParser::warn(std::string const& msg) const
514 { 514 {
515 - warn(input->getLastOffset(), msg); 515 + warn(input.getLastOffset(), msg);
516 } 516 }
libqpdf/qpdf/QPDFParser.hh
@@ -12,7 +12,7 @@ class QPDFParser @@ -12,7 +12,7 @@ class QPDFParser
12 public: 12 public:
13 QPDFParser() = delete; 13 QPDFParser() = delete;
14 QPDFParser( 14 QPDFParser(
15 - std::shared_ptr<InputSource> input, 15 + InputSource& input,
16 std::string const& object_description, 16 std::string const& object_description,
17 QPDFTokenizer& tokenizer, 17 QPDFTokenizer& tokenizer,
18 QPDFObjectHandle::StringDecrypter* decrypter, 18 QPDFObjectHandle::StringDecrypter* decrypter,
@@ -24,7 +24,7 @@ class QPDFParser @@ -24,7 +24,7 @@ class QPDFParser
24 decrypter(decrypter), 24 decrypter(decrypter),
25 context(context), 25 context(context),
26 description(std::make_shared<QPDFValue::Description>( 26 description(std::make_shared<QPDFValue::Description>(
27 - std::string(input->getName() + ", " + object_description + " at offset $PO"))), 27 + std::string(input.getName() + ", " + object_description + " at offset $PO"))),
28 parse_pdf(parse_pdf) 28 parse_pdf(parse_pdf)
29 { 29 {
30 } 30 }
@@ -39,9 +39,9 @@ class QPDFParser @@ -39,9 +39,9 @@ class QPDFParser
39 39
40 struct StackFrame 40 struct StackFrame
41 { 41 {
42 - StackFrame(std::shared_ptr<InputSource> const& input, parser_state_e state) : 42 + StackFrame(InputSource& input, parser_state_e state) :
43 state(state), 43 state(state),
44 - offset(input->tell()) 44 + offset(input.tell())
45 { 45 {
46 } 46 }
47 47
@@ -72,7 +72,7 @@ class QPDFParser @@ -72,7 +72,7 @@ class QPDFParser
72 // NB the offset includes any leading whitespace. 72 // NB the offset includes any leading whitespace.
73 QPDFObjectHandle withDescription(Args&&... args); 73 QPDFObjectHandle withDescription(Args&&... args);
74 void setDescription(std::shared_ptr<QPDFObject>& obj, qpdf_offset_t parsed_offset); 74 void setDescription(std::shared_ptr<QPDFObject>& obj, qpdf_offset_t parsed_offset);
75 - std::shared_ptr<InputSource> input; 75 + InputSource& input;
76 std::string const& object_description; 76 std::string const& object_description;
77 QPDFTokenizer& tokenizer; 77 QPDFTokenizer& tokenizer;
78 QPDFObjectHandle::StringDecrypter* decrypter; 78 QPDFObjectHandle::StringDecrypter* decrypter;