Commit 986a253cdd504c6e2c9d05c5af77e1b4578637bd

Authored by m-holger
1 parent 4783b223

Overload QPDFTokenizer::findEI to take a InputSource&

include/qpdf/QPDFTokenizer.hh
@@ -191,6 +191,8 @@ class QPDFTokenizer @@ -191,6 +191,8 @@ class QPDFTokenizer
191 // returns a tt_inline_image token. 191 // returns a tt_inline_image token.
192 QPDF_DLL 192 QPDF_DLL
193 void expectInlineImage(std::shared_ptr<InputSource> input); 193 void expectInlineImage(std::shared_ptr<InputSource> input);
  194 + QPDF_DLL
  195 + void expectInlineImage(InputSource& input);
194 196
195 private: 197 private:
196 friend class QPDFParser; 198 friend class QPDFParser;
@@ -217,7 +219,7 @@ class QPDFTokenizer @@ -217,7 +219,7 @@ class QPDFTokenizer
217 219
218 bool isSpace(char); 220 bool isSpace(char);
219 bool isDelimiter(char); 221 bool isDelimiter(char);
220 - void findEI(std::shared_ptr<InputSource> input); 222 + void findEI(InputSource& input);
221 223
222 enum state_e { 224 enum state_e {
223 st_top, 225 st_top,
libqpdf/QPDFTokenizer.cc
@@ -27,7 +27,7 @@ namespace @@ -27,7 +27,7 @@ namespace
27 class QPDFWordTokenFinder: public InputSource::Finder 27 class QPDFWordTokenFinder: public InputSource::Finder
28 { 28 {
29 public: 29 public:
30 - QPDFWordTokenFinder(std::shared_ptr<InputSource> is, std::string const& str) : 30 + QPDFWordTokenFinder(InputSource& is, std::string const& str) :
31 is(is), 31 is(is),
32 str(str) 32 str(str)
33 { 33 {
@@ -36,7 +36,7 @@ namespace @@ -36,7 +36,7 @@ namespace
36 bool check() override; 36 bool check() override;
37 37
38 private: 38 private:
39 - std::shared_ptr<InputSource> is; 39 + InputSource& is;
40 std::string str; 40 std::string str;
41 }; 41 };
42 } // namespace 42 } // namespace
@@ -48,21 +48,21 @@ QPDFWordTokenFinder::check() @@ -48,21 +48,21 @@ QPDFWordTokenFinder::check()
48 // delimiter or EOF. 48 // delimiter or EOF.
49 QPDFTokenizer tokenizer; 49 QPDFTokenizer tokenizer;
50 QPDFTokenizer::Token t = tokenizer.readToken(is, "finder", true); 50 QPDFTokenizer::Token t = tokenizer.readToken(is, "finder", true);
51 - qpdf_offset_t pos = is->tell(); 51 + qpdf_offset_t pos = is.tell();
52 if (!(t == QPDFTokenizer::Token(QPDFTokenizer::tt_word, str))) { 52 if (!(t == QPDFTokenizer::Token(QPDFTokenizer::tt_word, str))) {
53 QTC::TC("qpdf", "QPDFTokenizer finder found wrong word"); 53 QTC::TC("qpdf", "QPDFTokenizer finder found wrong word");
54 return false; 54 return false;
55 } 55 }
56 - qpdf_offset_t token_start = is->getLastOffset(); 56 + qpdf_offset_t token_start = is.getLastOffset();
57 char next; 57 char next;
58 bool next_okay = false; 58 bool next_okay = false;
59 - if (is->read(&next, 1) == 0) { 59 + if (is.read(&next, 1) == 0) {
60 QTC::TC("qpdf", "QPDFTokenizer inline image at EOF"); 60 QTC::TC("qpdf", "QPDFTokenizer inline image at EOF");
61 next_okay = true; 61 next_okay = true;
62 } else { 62 } else {
63 next_okay = is_delimiter(next); 63 next_okay = is_delimiter(next);
64 } 64 }
65 - is->seek(pos, SEEK_SET); 65 + is.seek(pos, SEEK_SET);
66 if (!next_okay) { 66 if (!next_okay) {
67 return false; 67 return false;
68 } 68 }
@@ -764,11 +764,17 @@ QPDFTokenizer::presentEOF() @@ -764,11 +764,17 @@ QPDFTokenizer::presentEOF()
764 void 764 void
765 QPDFTokenizer::expectInlineImage(std::shared_ptr<InputSource> input) 765 QPDFTokenizer::expectInlineImage(std::shared_ptr<InputSource> input)
766 { 766 {
  767 + expectInlineImage(*input);
  768 +}
  769 +
  770 +void
  771 +QPDFTokenizer::expectInlineImage(InputSource& input)
  772 +{
767 if (this->state == st_token_ready) { 773 if (this->state == st_token_ready) {
768 reset(); 774 reset();
769 } else if (this->state != st_before_token) { 775 } else if (this->state != st_before_token) {
770 - throw std::logic_error("QPDFTokenizer::expectInlineImage called"  
771 - " when tokenizer is in improper state"); 776 + throw std::logic_error(
  777 + "QPDFTokenizer::expectInlineImage called when tokenizer is in improper state");
772 } 778 }
773 findEI(input); 779 findEI(input);
774 this->before_token = false; 780 this->before_token = false;
@@ -777,14 +783,10 @@ QPDFTokenizer::expectInlineImage(std::shared_ptr&lt;InputSource&gt; input) @@ -777,14 +783,10 @@ QPDFTokenizer::expectInlineImage(std::shared_ptr&lt;InputSource&gt; input)
777 } 783 }
778 784
779 void 785 void
780 -QPDFTokenizer::findEI(std::shared_ptr<InputSource> input) 786 +QPDFTokenizer::findEI(InputSource& input)
781 { 787 {
782 - if (!input.get()) {  
783 - return;  
784 - }  
785 -  
786 - qpdf_offset_t last_offset = input->getLastOffset();  
787 - qpdf_offset_t pos = input->tell(); 788 + qpdf_offset_t last_offset = input.getLastOffset();
  789 + qpdf_offset_t pos = input.tell();
788 790
789 // Use QPDFWordTokenFinder to find EI surrounded by delimiters. Then read the next several 791 // Use QPDFWordTokenFinder to find EI surrounded by delimiters. Then read the next several
790 // tokens or up to EOF. If we find any suspicious-looking or tokens, this is probably still part 792 // tokens or up to EOF. If we find any suspicious-looking or tokens, this is probably still part
@@ -797,10 +799,10 @@ QPDFTokenizer::findEI(std::shared_ptr&lt;InputSource&gt; input) @@ -797,10 +799,10 @@ QPDFTokenizer::findEI(std::shared_ptr&lt;InputSource&gt; input)
797 bool first_try = true; 799 bool first_try = true;
798 while (!okay) { 800 while (!okay) {
799 QPDFWordTokenFinder f(input, "EI"); 801 QPDFWordTokenFinder f(input, "EI");
800 - if (!input->findFirst("EI", input->tell(), 0, f)) { 802 + if (!input.findFirst("EI", input.tell(), 0, f)) {
801 break; 803 break;
802 } 804 }
803 - this->inline_image_bytes = QIntC::to_size(input->tell() - pos - 2); 805 + inline_image_bytes = QIntC::to_size(input.tell() - pos - 2);
804 806
805 QPDFTokenizer check; 807 QPDFTokenizer check;
806 bool found_bad = false; 808 bool found_bad = false;
@@ -858,8 +860,8 @@ QPDFTokenizer::findEI(std::shared_ptr&lt;InputSource&gt; input) @@ -858,8 +860,8 @@ QPDFTokenizer::findEI(std::shared_ptr&lt;InputSource&gt; input)
858 QTC::TC("qpdf", "QPDFTokenizer found EI after more than one try"); 860 QTC::TC("qpdf", "QPDFTokenizer found EI after more than one try");
859 } 861 }
860 862
861 - input->seek(pos, SEEK_SET);  
862 - input->setLastOffset(last_offset); 863 + input.seek(pos, SEEK_SET);
  864 + input.setLastOffset(last_offset);
863 } 865 }
864 866
865 bool 867 bool