aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2018-01-30 03:34:24 +0100
committerJay Berkenbilt <ejb@ql.org>2018-02-19 03:05:46 +0100
commit55ee55394c1434da62c01e01a537eee5aa909eba (patch)
tree014e03501b6547bb71c7ddf8433773a37a5c00bb /libqpdf
parentba453ba4fff442dc03ea04a3328aaa58bb8e6923 (diff)
downloadqpdf-55ee55394c1434da62c01e01a537eee5aa909eba.tar.zst
Use inline image token in content parser
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDFObjectHandle.cc49
1 files changed, 19 insertions, 30 deletions
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc
index 247b3b38..1fa02427 100644
--- a/libqpdf/QPDFObjectHandle.cc
+++ b/libqpdf/QPDFObjectHandle.cc
@@ -907,42 +907,31 @@ QPDFObjectHandle::parseContentStream_internal(PointerHolder<Buffer> stream_data,
// terminated the token. Read until end of inline image.
char ch;
input->read(&ch, 1);
- char buf[4];
- memset(buf, '\0', sizeof(buf));
- bool done = false;
- std::string inline_image;
- while (! done)
+ tokenizer.expectInlineImage();
+ QPDFTokenizer::Token t = tokenizer.readToken(input, description, true);
+ if (t.getType() == QPDFTokenizer::tt_bad)
{
- if (input->read(&ch, 1) == 0)
- {
- QTC::TC("qpdf", "QPDFObjectHandle EOF in inline image");
- throw QPDFExc(qpdf_e_damaged_pdf, input->getName(),
- "stream data", input->tell(),
- "EOF found while reading inline image");
- }
- inline_image += ch;
- memmove(buf, buf + 1, sizeof(buf) - 1);
- buf[sizeof(buf) - 1] = ch;
- if (strchr(" \t\n\v\f\r", buf[0]) &&
- (buf[1] == 'E') &&
- (buf[2] == 'I') &&
- strchr(" \t\n\v\f\r", buf[3]))
+ QTC::TC("qpdf", "QPDFObjectHandle EOF in inline image");
+ throw QPDFExc(qpdf_e_damaged_pdf, input->getName(),
+ "stream data", input->tell(),
+ "EOF found while reading inline image");
+ }
+ else
+ {
+ // Skip back over EI
+ input->seek(-3, SEEK_CUR);
+ std::string inline_image = t.getRawValue();
+ for (int i = 0; i < 4; ++i)
{
- // We've found an EI operator.
- done = true;
- input->seek(-3, SEEK_CUR);
- for (int i = 0; i < 4; ++i)
+ if (inline_image.length() > 0)
{
- if (inline_image.length() > 0)
- {
- inline_image.erase(inline_image.length() - 1);
- }
+ inline_image.erase(inline_image.length() - 1);
}
}
+ QTC::TC("qpdf", "QPDFObjectHandle inline image token");
+ callbacks->handleObject(
+ QPDFObjectHandle::newInlineImage(inline_image));
}
- QTC::TC("qpdf", "QPDFObjectHandle inline image token");
- callbacks->handleObject(
- QPDFObjectHandle::newInlineImage(inline_image));
}
}
}