mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 19:08:59 +00:00
Refactor QPDF::isLinearized
This commit is contained in:
parent
b21973618b
commit
f92368f44f
@ -18,6 +18,8 @@
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
template <class T, class int_type>
|
||||
static void
|
||||
load_vector_int(
|
||||
@ -95,25 +97,17 @@ QPDF::isLinearized()
|
||||
// The PDF spec says the linearization dictionary must be completely contained within the first
|
||||
// 1024 bytes of the file. Add a byte for a null terminator.
|
||||
auto buffer = m->file->read(1024, 0);
|
||||
|
||||
auto buf = buffer.data();
|
||||
auto tbuf_size = buffer.size();
|
||||
int lindict_obj = -1;
|
||||
char* p = buf;
|
||||
size_t pos = 0;
|
||||
while (lindict_obj == -1) {
|
||||
// Find a digit or end of buffer
|
||||
while (((p - buf) < tbuf_size) && (!QUtil::is_digit(*p))) {
|
||||
++p;
|
||||
}
|
||||
if (p - buf == tbuf_size) {
|
||||
break;
|
||||
pos = buffer.find_first_of("0123456789"sv, pos);
|
||||
if (pos == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
// Seek to the digit. Then skip over digits for a potential
|
||||
// next iteration.
|
||||
m->file->seek(p - buf, SEEK_SET);
|
||||
while (((p - buf) < tbuf_size) && QUtil::is_digit(*p)) {
|
||||
++p;
|
||||
}
|
||||
m->file->seek(toO(pos), SEEK_SET);
|
||||
|
||||
QPDFTokenizer::Token t1 = readToken(*m->file);
|
||||
if (t1.isInteger() && readToken(*m->file).isInteger() &&
|
||||
@ -121,6 +115,10 @@ QPDF::isLinearized()
|
||||
readToken(*m->file).getType() == QPDFTokenizer::tt_dict_open) {
|
||||
lindict_obj = toI(QUtil::string_to_ll(t1.getValue().c_str()));
|
||||
}
|
||||
pos = buffer.find_first_not_of("0123456789"sv, pos);
|
||||
if (pos == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (lindict_obj <= 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user