[poppler] Patch to check for eof when loading a file

Kristian Høgsberg krh at bitplanet.net
Tue Jul 5 17:36:57 PDT 2005


Albert Astals Cid wrote:
> Hi, in kpdf we have implemented automatic reload once the file changes, that 
> is causing us some problems because kdirwatch may warn us several times and 
> only the last is the good one, this is causing that sometimes we crash 
> because we try to open a non complete file. I have been wondering if that 
> patch could help us.
> 
> What do you think, can it be of any use?
> 
> Can i commit it to the cvs?

Yep, go ahead, sounds like a good check to add.  Maybe put the check in 
a PDFDoc::checkFooter() method, similar to checkHeader().

> Albert
> 
> 
> ------------------------------------------------------------------------
> 
> Index: PDFDoc.cc
> ===================================================================
> RCS file: /cvs/poppler/poppler/poppler/PDFDoc.cc,v
> retrieving revision 1.1.1.1
> diff -u -r1.1.1.1 PDFDoc.cc
> --- PDFDoc.cc	3 Mar 2005 19:46:03 -0000	1.1.1.1
> +++ PDFDoc.cc	3 Jul 2005 18:25:59 -0000
> @@ -116,6 +116,25 @@
>  GBool PDFDoc::setup(GooString *ownerPassword, GooString *userPassword) {
>    str->reset();
>  
> +  char eof[8];
> +  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';
> +  if (strstr(eof, "%%EOF") == NULL)
> +  {
> +    error(-1, "Document does not has ending %%EOF");
> +    errCode = errDamaged;
> +    return gFalse;
> +  }
> +  str->setPos(pos);
> +			
>    // check header
>    checkHeader();
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> poppler mailing list
> poppler at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/poppler



More information about the poppler mailing list