From 55ee55394c1434da62c01e01a537eee5aa909eba Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Mon, 29 Jan 2018 21:34:24 -0500 Subject: Use inline image token in content parser --- libqpdf/QPDFObjectHandle.cc | 49 ++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 30 deletions(-) (limited to 'libqpdf') 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 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)); } } } -- cgit v1.2.3-54-g00ecf