Commit 986a253cdd504c6e2c9d05c5af77e1b4578637bd
1 parent
4783b223
Overload QPDFTokenizer::findEI to take a InputSource&
Showing
2 changed files
with
24 additions
and
20 deletions
include/qpdf/QPDFTokenizer.hh
| ... | ... | @@ -191,6 +191,8 @@ class QPDFTokenizer |
| 191 | 191 | // returns a tt_inline_image token. |
| 192 | 192 | QPDF_DLL |
| 193 | 193 | void expectInlineImage(std::shared_ptr<InputSource> input); |
| 194 | + QPDF_DLL | |
| 195 | + void expectInlineImage(InputSource& input); | |
| 194 | 196 | |
| 195 | 197 | private: |
| 196 | 198 | friend class QPDFParser; |
| ... | ... | @@ -217,7 +219,7 @@ class QPDFTokenizer |
| 217 | 219 | |
| 218 | 220 | bool isSpace(char); |
| 219 | 221 | bool isDelimiter(char); |
| 220 | - void findEI(std::shared_ptr<InputSource> input); | |
| 222 | + void findEI(InputSource& input); | |
| 221 | 223 | |
| 222 | 224 | enum state_e { |
| 223 | 225 | st_top, | ... | ... |
libqpdf/QPDFTokenizer.cc
| ... | ... | @@ -27,7 +27,7 @@ namespace |
| 27 | 27 | class QPDFWordTokenFinder: public InputSource::Finder |
| 28 | 28 | { |
| 29 | 29 | public: |
| 30 | - QPDFWordTokenFinder(std::shared_ptr<InputSource> is, std::string const& str) : | |
| 30 | + QPDFWordTokenFinder(InputSource& is, std::string const& str) : | |
| 31 | 31 | is(is), |
| 32 | 32 | str(str) |
| 33 | 33 | { |
| ... | ... | @@ -36,7 +36,7 @@ namespace |
| 36 | 36 | bool check() override; |
| 37 | 37 | |
| 38 | 38 | private: |
| 39 | - std::shared_ptr<InputSource> is; | |
| 39 | + InputSource& is; | |
| 40 | 40 | std::string str; |
| 41 | 41 | }; |
| 42 | 42 | } // namespace |
| ... | ... | @@ -48,21 +48,21 @@ QPDFWordTokenFinder::check() |
| 48 | 48 | // delimiter or EOF. |
| 49 | 49 | QPDFTokenizer tokenizer; |
| 50 | 50 | QPDFTokenizer::Token t = tokenizer.readToken(is, "finder", true); |
| 51 | - qpdf_offset_t pos = is->tell(); | |
| 51 | + qpdf_offset_t pos = is.tell(); | |
| 52 | 52 | if (!(t == QPDFTokenizer::Token(QPDFTokenizer::tt_word, str))) { |
| 53 | 53 | QTC::TC("qpdf", "QPDFTokenizer finder found wrong word"); |
| 54 | 54 | return false; |
| 55 | 55 | } |
| 56 | - qpdf_offset_t token_start = is->getLastOffset(); | |
| 56 | + qpdf_offset_t token_start = is.getLastOffset(); | |
| 57 | 57 | char next; |
| 58 | 58 | bool next_okay = false; |
| 59 | - if (is->read(&next, 1) == 0) { | |
| 59 | + if (is.read(&next, 1) == 0) { | |
| 60 | 60 | QTC::TC("qpdf", "QPDFTokenizer inline image at EOF"); |
| 61 | 61 | next_okay = true; |
| 62 | 62 | } else { |
| 63 | 63 | next_okay = is_delimiter(next); |
| 64 | 64 | } |
| 65 | - is->seek(pos, SEEK_SET); | |
| 65 | + is.seek(pos, SEEK_SET); | |
| 66 | 66 | if (!next_okay) { |
| 67 | 67 | return false; |
| 68 | 68 | } |
| ... | ... | @@ -764,11 +764,17 @@ QPDFTokenizer::presentEOF() |
| 764 | 764 | void |
| 765 | 765 | QPDFTokenizer::expectInlineImage(std::shared_ptr<InputSource> input) |
| 766 | 766 | { |
| 767 | + expectInlineImage(*input); | |
| 768 | +} | |
| 769 | + | |
| 770 | +void | |
| 771 | +QPDFTokenizer::expectInlineImage(InputSource& input) | |
| 772 | +{ | |
| 767 | 773 | if (this->state == st_token_ready) { |
| 768 | 774 | reset(); |
| 769 | 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 | 779 | findEI(input); |
| 774 | 780 | this->before_token = false; |
| ... | ... | @@ -777,14 +783,10 @@ QPDFTokenizer::expectInlineImage(std::shared_ptr<InputSource> input) |
| 777 | 783 | } |
| 778 | 784 | |
| 779 | 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 | 791 | // Use QPDFWordTokenFinder to find EI surrounded by delimiters. Then read the next several |
| 790 | 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<InputSource> input) |
| 797 | 799 | bool first_try = true; |
| 798 | 800 | while (!okay) { |
| 799 | 801 | QPDFWordTokenFinder f(input, "EI"); |
| 800 | - if (!input->findFirst("EI", input->tell(), 0, f)) { | |
| 802 | + if (!input.findFirst("EI", input.tell(), 0, f)) { | |
| 801 | 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 | 807 | QPDFTokenizer check; |
| 806 | 808 | bool found_bad = false; |
| ... | ... | @@ -858,8 +860,8 @@ QPDFTokenizer::findEI(std::shared_ptr<InputSource> input) |
| 858 | 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 | 867 | bool | ... | ... |