[poppler] Increase %%EOF searching

Kristian Høgsberg krh at bitplanet.net
Sat Aug 6 01:22:01 EST 2005


Albert Astals Cid wrote:
> Good chatch, what about this then?
> 
> I've checked and doing
> 
> str->setPos(1024, -1);
> 
> does not hurt as it already checks if the file is large enough and does only 
> "rewind" the size if < 1024.

Almost there... see below

>>--- poppler/PDFDoc.cc	6 Jul 2005 13:29:00 -0000	1.2
>>+++ poppler/PDFDoc.cc	3 Aug 2005 18:47:17 -0000
>>@@ -177,23 +177,24 @@
>> // Check for a %%EOF at the end of this stream
>> GBool PDFDoc::checkFooter() {
>>   // we look in the last 7 chars because it can be %%EOF %%EOF\n %%EOF\n\r etc
>>-  char eof[8];
>>+  char *eof = new char[1025];
>>   int pos = str->getPos();
>>-  str->setPos(7, -1);
>>-  eof[0] = str->getChar();
>>-  eof[1] = str->getChar();
>>-  eof[2] = str->getChar();
>>-  eof[3] = str->getChar();
>>-  eof[4] = str->getChar();
>>-  eof[5] = str->getChar();
>>-  eof[6] = str->getChar();
>>-  eof[7] = '\0';
>>+  str->setPos(1024, -1);
>>+  int i;
>>+  for (i = 0; i < 1024; i++)
>>+  {
>>+    eof[i] = str->getChar();
>>+    if (eof[i] == EOF) break;

This will break if there a 0xff char in the PDF file.  eof[i] is a 
signed char and 0xff will be converted to -1 (== EOF) as it's assigned 
to it.  You need to use a temporary int variable to properly distinguish 
between the char 0xff and EOF:

   int ch;

   for (i = 0; i < 1024; i++) {
     ch = str->getChar();
     if (ch == EOF)
       break;
     eof[i] = ch;
   }

cheers,
Kristian


More information about the poppler mailing list