Commit 90840be59448ba92974629c34ef1b844ccf6a0aa

Authored by Jay Berkenbilt
1 parent 03aa9679

Find lindict without PCRE

libqpdf/QPDF_linearization.cc
... ... @@ -5,7 +5,6 @@
5 5 #include <qpdf/QPDFExc.hh>
6 6 #include <qpdf/QTC.hh>
7 7 #include <qpdf/QUtil.hh>
8   -#include <qpdf/PCRE.hh>
9 8 #include <qpdf/Pl_Buffer.hh>
10 9 #include <qpdf/Pl_Flate.hh>
11 10 #include <qpdf/Pl_Count.hh>
... ... @@ -101,38 +100,42 @@ QPDF::isLinearized()
101 100 memset(buf, '\0', tbuf_size);
102 101 this->file->read(buf, tbuf_size - 1);
103 102  
104   - PCRE lindict_re("(?s:(\\d+)\\s+0\\s+obj\\s*<<)");
105   -
106 103 int lindict_obj = -1;
107 104 char* p = buf;
108 105 while (lindict_obj == -1)
109 106 {
110   - PCRE::Match m(lindict_re.match(p));
111   - if (m)
112   - {
113   - lindict_obj = atoi(m.getMatch(1).c_str());
114   - if (m.getMatch(0).find('\n') != std::string::npos)
115   - {
116   - QTC::TC("qpdf", "QPDF lindict found newline");
117   - }
118   - }
119   - else
120   - {
121   - p = static_cast<char*>(memchr(p, '\0', tbuf_size - (p - buf)));
122   - assert(p != 0);
123   - while ((p - buf < tbuf_size) && (*p == 0))
124   - {
125   - ++p;
126   - }
127   - if ((p - buf) == tbuf_size)
128   - {
129   - break;
130   - }
131   - QTC::TC("qpdf", "QPDF lindict searching after null");
  107 + // Find a digit or end of buffer
  108 + while (((p - buf) < tbuf_size) && (! QUtil::is_digit(*p)))
  109 + {
  110 + ++p;
  111 + }
  112 + if (p - buf == tbuf_size)
  113 + {
  114 + break;
  115 + }
  116 + // Seek to the digit. Then skip over digits for a potential
  117 + // next iteration.
  118 + this->file->seek(p - buf, SEEK_SET);
  119 + while (((p - buf) < tbuf_size) && QUtil::is_digit(*p))
  120 + {
  121 + ++p;
  122 + }
  123 +
  124 + QPDFTokenizer::Token t1 = readToken(this->file, true);
  125 + QPDFTokenizer::Token t2 = readToken(this->file, true);
  126 + QPDFTokenizer::Token t3 = readToken(this->file, true);
  127 + QPDFTokenizer::Token t4 = readToken(this->file, true);
  128 + if ((t1.getType() == QPDFTokenizer::tt_integer) &&
  129 + (t2.getType() == QPDFTokenizer::tt_integer) &&
  130 + (t3 == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "obj")) &&
  131 + (t4.getType() == QPDFTokenizer::tt_dict_open))
  132 + {
  133 + lindict_obj =
  134 + static_cast<int>(QUtil::string_to_ll(t1.getValue().c_str()));
132 135 }
133 136 }
134 137  
135   - if (lindict_obj == 0)
  138 + if (lindict_obj <= 0)
136 139 {
137 140 return false;
138 141 }
... ...
qpdf/qpdf.testcov
1 1 ignored-scope: libtests
2   -QPDF lindict searching after null 0
3 2 QPDF err expected endobj 0
4 3 QPDF err wrong objid/generation 0
5 4 QPDF check objid 1
... ... @@ -10,7 +9,6 @@ QPDF hint table length direct 0
10 9 QPDF P absent in lindict 0
11 10 QPDF P present in lindict 0
12 11 QPDF expected n n obj 0
13   -QPDF lindict found newline 0
14 12 QPDF /L mismatch 0
15 13 QPDF err /T mismatch 0
16 14 QPDF err /O mismatch 0
... ...