2
1
mirror of https://github.com/qpdf/qpdf.git synced 2025-01-09 09:50:28 +00:00

Find lindict without PCRE

This commit is contained in:
Jay Berkenbilt 2017-08-09 20:17:18 -04:00
parent 03aa9679ac
commit 90840be594
2 changed files with 29 additions and 28 deletions

View File

@ -5,7 +5,6 @@
#include <qpdf/QPDFExc.hh> #include <qpdf/QPDFExc.hh>
#include <qpdf/QTC.hh> #include <qpdf/QTC.hh>
#include <qpdf/QUtil.hh> #include <qpdf/QUtil.hh>
#include <qpdf/PCRE.hh>
#include <qpdf/Pl_Buffer.hh> #include <qpdf/Pl_Buffer.hh>
#include <qpdf/Pl_Flate.hh> #include <qpdf/Pl_Flate.hh>
#include <qpdf/Pl_Count.hh> #include <qpdf/Pl_Count.hh>
@ -101,38 +100,42 @@ QPDF::isLinearized()
memset(buf, '\0', tbuf_size); memset(buf, '\0', tbuf_size);
this->file->read(buf, tbuf_size - 1); this->file->read(buf, tbuf_size - 1);
PCRE lindict_re("(?s:(\\d+)\\s+0\\s+obj\\s*<<)");
int lindict_obj = -1; int lindict_obj = -1;
char* p = buf; char* p = buf;
while (lindict_obj == -1) while (lindict_obj == -1)
{ {
PCRE::Match m(lindict_re.match(p)); // Find a digit or end of buffer
if (m) while (((p - buf) < tbuf_size) && (! QUtil::is_digit(*p)))
{ {
lindict_obj = atoi(m.getMatch(1).c_str()); ++p;
if (m.getMatch(0).find('\n') != std::string::npos) }
{ if (p - buf == tbuf_size)
QTC::TC("qpdf", "QPDF lindict found newline"); {
} break;
} }
else // Seek to the digit. Then skip over digits for a potential
{ // next iteration.
p = static_cast<char*>(memchr(p, '\0', tbuf_size - (p - buf))); this->file->seek(p - buf, SEEK_SET);
assert(p != 0); while (((p - buf) < tbuf_size) && QUtil::is_digit(*p))
while ((p - buf < tbuf_size) && (*p == 0)) {
{ ++p;
++p; }
}
if ((p - buf) == tbuf_size) QPDFTokenizer::Token t1 = readToken(this->file, true);
{ QPDFTokenizer::Token t2 = readToken(this->file, true);
break; QPDFTokenizer::Token t3 = readToken(this->file, true);
} QPDFTokenizer::Token t4 = readToken(this->file, true);
QTC::TC("qpdf", "QPDF lindict searching after null"); if ((t1.getType() == QPDFTokenizer::tt_integer) &&
(t2.getType() == QPDFTokenizer::tt_integer) &&
(t3 == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "obj")) &&
(t4.getType() == QPDFTokenizer::tt_dict_open))
{
lindict_obj =
static_cast<int>(QUtil::string_to_ll(t1.getValue().c_str()));
} }
} }
if (lindict_obj == 0) if (lindict_obj <= 0)
{ {
return false; return false;
} }

View File

@ -1,5 +1,4 @@
ignored-scope: libtests ignored-scope: libtests
QPDF lindict searching after null 0
QPDF err expected endobj 0 QPDF err expected endobj 0
QPDF err wrong objid/generation 0 QPDF err wrong objid/generation 0
QPDF check objid 1 QPDF check objid 1
@ -10,7 +9,6 @@ QPDF hint table length direct 0
QPDF P absent in lindict 0 QPDF P absent in lindict 0
QPDF P present in lindict 0 QPDF P present in lindict 0
QPDF expected n n obj 0 QPDF expected n n obj 0
QPDF lindict found newline 0
QPDF /L mismatch 0 QPDF /L mismatch 0
QPDF err /T mismatch 0 QPDF err /T mismatch 0
QPDF err /O mismatch 0 QPDF err /O mismatch 0