From 5b6c21b2446b4a04f4cc4ac82a617ebb2b871c8d Mon Sep 17 00:00:00 2001 From: Evangelos Foutras Date: Thu, 22 Mar 2018 03:41:23 +0200 Subject: [PATCH] Fix PDFDoc::checkHeader() for PDFs smaller than 1 KiB The fix for bug 104502 made it so PDFDoc::checkHeader() would print a warning and return immediatelly if it encounters an EOF while reading the first 1024 bytes. Some PDF files can be smaller than 1024 bytes, for example those used by pdf2djvu's test suite. The latter would fail due to the unexpected warnings. Change the behavior of PDFDoc::checkHeader() when encountering an EOF so it processes the data it has read so far instead of aborting early. https://bugs.freedesktop.org/show_bug.cgi?id=105674 --- poppler/PDFDoc.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc index 6789c39f..d7149b1d 100644 --- a/poppler/PDFDoc.cc +++ b/poppler/PDFDoc.cc @@ -408,25 +408,23 @@ void PDFDoc::checkHeader() { char hdrBuf[headerSearchSize+1]; char *p; char *tokptr; - int i; - int c; + int c, n, i; pdfMajorVersion = 0; pdfMinorVersion = 0; - for (i = 0; i < headerSearchSize; ++i) { + for (n = 0; n < headerSearchSize; ++n) { if ((c = str->getChar()) == EOF) { - error(errSyntaxWarning, -1, "EOF while reading header (continuing anyway)"); - return; + break; } - hdrBuf[i] = c; + hdrBuf[n] = c; } - hdrBuf[headerSearchSize] = '\0'; - for (i = 0; i < headerSearchSize - 5; ++i) { + hdrBuf[n] = '\0'; + for (i = 0; i < n - 5; ++i) { if (!strncmp(&hdrBuf[i], "%PDF-", 5)) { break; } } - if (i >= headerSearchSize - 5) { + if (i >= n - 5) { error(errSyntaxWarning, -1, "May not be a PDF file (continuing anyway)"); return; } -- 2.16.2