aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDF.cc14
-rw-r--r--libqpdf/QUtil.cc4
2 files changed, 12 insertions, 6 deletions
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc
index 295787b1..fc3120bb 100644
--- a/libqpdf/QPDF.cc
+++ b/libqpdf/QPDF.cc
@@ -477,15 +477,21 @@ QPDF::read_xref(qpdf_offset_t xref_offset)
// The PDF spec says xref must be followed by a line
// terminator, but files exist in the wild where it is
// terminated by arbitrary whitespace.
- PCRE xref_re("^xref\\s+");
- PCRE::Match m = xref_re.match(buf);
- if (m)
+ if ((strncmp(buf, "xref", 4) == 0) &&
+ QUtil::is_space(buf[4]))
{
QTC::TC("qpdf", "QPDF xref space",
((buf[4] == '\n') ? 0 :
(buf[4] == '\r') ? 1 :
(buf[4] == ' ') ? 2 : 9999));
- xref_offset = read_xrefTable(xref_offset + m.getMatch(0).length());
+ int skip = 4;
+ // buf is null-terminated, and QUtil::is_space('\0') is
+ // false, so this won't overrun.
+ while (QUtil::is_space(buf[skip]))
+ {
+ ++skip;
+ }
+ xref_offset = read_xrefTable(xref_offset + skip);
}
else
{
diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc
index 29217cc6..10ca7d3b 100644
--- a/libqpdf/QUtil.cc
+++ b/libqpdf/QUtil.cc
@@ -511,13 +511,13 @@ QUtil::srandom(unsigned int seed)
bool
QUtil::is_hex_digit(char ch)
{
- return (strchr("0123456789abcdefABCDEF", ch) != 0);
+ return (ch && (strchr("0123456789abcdefABCDEF", ch) != 0));
}
bool
QUtil::is_space(char ch)
{
- return (strchr(" \f\n\r\t\v", ch) != 0);
+ return (ch && (strchr(" \f\n\r\t\v", ch) != 0));
}
bool