]> www.fi.muni.cz Git - evince.git/blobdiff - pdf/xpdf/Parser.cc
Fixup selection offset calculation
[evince.git] / pdf / xpdf / Parser.cc
index 4bcb0ceb87d30f846bd842ab5a3e56537f226544..0aa66d32ef0cdf33b18b25c9955d2e948bfd3eab 100644 (file)
@@ -2,7 +2,7 @@
 //
 // Parser.cc
 //
 //
 // Parser.cc
 //
-// Copyright 1996-2002 Glyph & Cog, LLC
+// Copyright 1996-2003 Glyph & Cog, LLC
 //
 //========================================================================
 
 //
 //========================================================================
 
@@ -176,10 +176,16 @@ Stream *Parser::makeStream(Object *dict) {
   }
 
   // check for length in damaged file
   }
 
   // check for length in damaged file
-  if (xref->getStreamEnd(pos, &endPos)) {
+  if (xref && xref->getStreamEnd(pos, &endPos)) {
     length = endPos - pos;
   }
 
     length = endPos - pos;
   }
 
+  // in badly damaged PDF files, we can run off the end of the input
+  // stream immediately after the "stream" token
+  if (!lexer->getStream()) {
+    return NULL;
+  }
+
   // make base stream
   str = lexer->getStream()->getBaseStream()->makeSubStream(pos, gTrue,
                                                           length, dict);
   // make base stream
   str = lexer->getStream()->getBaseStream()->makeSubStream(pos, gTrue,
                                                           length, dict);
@@ -193,10 +199,12 @@ Stream *Parser::makeStream(Object *dict) {
   // refill token buffers and check for 'endstream'
   shift();  // kill '>>'
   shift();  // kill 'stream'
   // refill token buffers and check for 'endstream'
   shift();  // kill '>>'
   shift();  // kill 'stream'
-  if (buf1.isCmd("endstream"))
+  if (buf1.isCmd("endstream")) {
     shift();
     shift();
-  else
+  } else {
     error(getPos(), "Missing 'endstream'");
     error(getPos(), "Missing 'endstream'");
+    str->ignoreLength();
+  }
 
   return str;
 }
 
   return str;
 }