Commit 55ee55394c1434da62c01e01a537eee5aa909eba

Authored by Jay Berkenbilt
1 parent ba453ba4

Use inline image token in content parser

Showing 1 changed file with 19 additions and 30 deletions
libqpdf/QPDFObjectHandle.cc
@@ -907,42 +907,31 @@ QPDFObjectHandle::parseContentStream_internal(PointerHolder<Buffer> stream_data, @@ -907,42 +907,31 @@ QPDFObjectHandle::parseContentStream_internal(PointerHolder<Buffer> stream_data,
907 // terminated the token. Read until end of inline image. 907 // terminated the token. Read until end of inline image.
908 char ch; 908 char ch;
909 input->read(&ch, 1); 909 input->read(&ch, 1);
910 - char buf[4];  
911 - memset(buf, '\0', sizeof(buf));  
912 - bool done = false;  
913 - std::string inline_image;  
914 - while (! done) 910 + tokenizer.expectInlineImage();
  911 + QPDFTokenizer::Token t = tokenizer.readToken(input, description, true);
  912 + if (t.getType() == QPDFTokenizer::tt_bad)
915 { 913 {
916 - if (input->read(&ch, 1) == 0)  
917 - {  
918 - QTC::TC("qpdf", "QPDFObjectHandle EOF in inline image");  
919 - throw QPDFExc(qpdf_e_damaged_pdf, input->getName(),  
920 - "stream data", input->tell(),  
921 - "EOF found while reading inline image");  
922 - }  
923 - inline_image += ch;  
924 - memmove(buf, buf + 1, sizeof(buf) - 1);  
925 - buf[sizeof(buf) - 1] = ch;  
926 - if (strchr(" \t\n\v\f\r", buf[0]) &&  
927 - (buf[1] == 'E') &&  
928 - (buf[2] == 'I') &&  
929 - strchr(" \t\n\v\f\r", buf[3])) 914 + QTC::TC("qpdf", "QPDFObjectHandle EOF in inline image");
  915 + throw QPDFExc(qpdf_e_damaged_pdf, input->getName(),
  916 + "stream data", input->tell(),
  917 + "EOF found while reading inline image");
  918 + }
  919 + else
  920 + {
  921 + // Skip back over EI
  922 + input->seek(-3, SEEK_CUR);
  923 + std::string inline_image = t.getRawValue();
  924 + for (int i = 0; i < 4; ++i)
930 { 925 {
931 - // We've found an EI operator.  
932 - done = true;  
933 - input->seek(-3, SEEK_CUR);  
934 - for (int i = 0; i < 4; ++i) 926 + if (inline_image.length() > 0)
935 { 927 {
936 - if (inline_image.length() > 0)  
937 - {  
938 - inline_image.erase(inline_image.length() - 1);  
939 - } 928 + inline_image.erase(inline_image.length() - 1);
940 } 929 }
941 } 930 }
  931 + QTC::TC("qpdf", "QPDFObjectHandle inline image token");
  932 + callbacks->handleObject(
  933 + QPDFObjectHandle::newInlineImage(inline_image));
942 } 934 }
943 - QTC::TC("qpdf", "QPDFObjectHandle inline image token");  
944 - callbacks->handleObject(  
945 - QPDFObjectHandle::newInlineImage(inline_image));  
946 } 935 }
947 } 936 }
948 } 937 }