Commit 3a1646c2 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Add checkFooter to check the document ends with %%EOF

parent 377c023d
2005-07-06 Albert Astals Cid <aacid@kde.org>
* poppler/PDFDoc.[cc|h]: Add checkFooter to check document ends with
%%EOF
2005-07-06 Brad Hards <bradh@frogmouth.net>
* qt4/tests/Makefile.am:
......
......@@ -116,6 +116,9 @@ PDFDoc::PDFDoc(BaseStream *strA, GooString *ownerPassword,
GBool PDFDoc::setup(GooString *ownerPassword, GooString *userPassword) {
str->reset();
// check footer
if (!checkFooter()) return gFalse;
// check header
checkHeader();
......@@ -170,6 +173,31 @@ PDFDoc::~PDFDoc() {
}
}
// 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];
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 has not the mandatory ending %%EOF");
errCode = errDamaged;
return gFalse;
}
str->setPos(pos);
return gTrue;
}
// Check for a PDF header on this stream. Skip past some garbage
// if necessary.
void PDFDoc::checkHeader() {
......
......@@ -164,6 +164,7 @@ public:
private:
GBool setup(GooString *ownerPassword, GooString *userPassword);
GBool checkFooter();
void checkHeader();
void getLinks(Page *page);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment