diff --git a/ChangeLog b/ChangeLog index 5484137e..083ed314 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2010-09-05 Jay Berkenbilt + * libqpdf/QPDF.cc (readObjectInternal): Recognize empty objects + and treat them as null. + * libqpdf/QPDF_Stream.cc (filterable): Handle inline image filter abbreviations as stream filter abbreviations. Although this is not technically allowed by the PDF specification, table H.1 in the diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 0ee097d5..2d8f55a1 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -1197,6 +1197,20 @@ QPDF::readObjectInternal(InputSource* input, olist.pop_back(); olist.pop_back(); } + else if ((value == "endobj") && + (! (in_array || in_dictionary))) + { + // Nothing in the PDF spec appears to allow empty + // objects, but they have been encountered in + // actual PDF files and Adobe Reader appears to + // ignore them. + warn(QPDFExc(qpdf_e_damaged_pdf, input->getName(), + this->last_object_description, + input->getLastOffset(), + "empty object treated as null")); + object = QPDFObjectHandle::newNull(); + input->seek(input->getLastOffset(), SEEK_SET); + } else { throw QPDFExc(qpdf_e_damaged_pdf, input->getName(), diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index c6040bf8..fd787364 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -111,7 +111,7 @@ $td->runtest("new stream", show_ntests(); # ---------- $td->notify("--- Miscellaneous Tests ---"); -$n_tests += 25; +$n_tests += 26; $td->runtest("qpdf version", {$td->COMMAND => "qpdf --version"}, @@ -239,6 +239,12 @@ $td->runtest("check output", {$td->FILE => "a.pdf"}, {$td->FILE => "filter-abbreviation.out"}); +$td->runtest("empty object", + {$td->COMMAND => "qpdf -show-object=7,0 empty-object.pdf"}, + {$td->FILE => "empty-object.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); + show_ntests(); # ---------- $td->notify("--- Error Condition Tests ---"); diff --git a/qpdf/qtest/qpdf/empty-object.out b/qpdf/qtest/qpdf/empty-object.out new file mode 100644 index 00000000..78274f8a --- /dev/null +++ b/qpdf/qtest/qpdf/empty-object.out @@ -0,0 +1,3 @@ +WARNING: empty-object.pdf (object 7 0, file position 575): empty object treated as null +null +qpdf: operation succeeded with warnings; resulting file may have some problems diff --git a/qpdf/qtest/qpdf/empty-object.pdf b/qpdf/qtest/qpdf/empty-object.pdf new file mode 100644 index 00000000..55eef2ac --- /dev/null +++ b/qpdf/qtest/qpdf/empty-object.pdf @@ -0,0 +1,84 @@ +%PDF-1.3 +1 0 obj +<< + /Type /Catalog + /Pages 2 0 R + /X 7 0 R +>> +endobj + +2 0 obj +<< + /Type /Pages + /Kids [ + 3 0 R + ] + /Count 1 +>> +endobj + +3 0 obj +<< + /Type /Page + /Parent 2 0 R + /MediaBox [0 0 612 792] + /Contents 4 0 R + /Resources << + /ProcSet 5 0 R + /Font << + /F1 6 0 R + >> + >> +>> +endobj + +4 0 obj +<< + /Length 44 +>> +stream +BT + /F1 24 Tf + 72 720 Td + (Potato) Tj +ET +endstream +endobj + +5 0 obj +[ + /PDF + /Text +] +endobj + +6 0 obj +<< + /Type /Font + /Subtype /Type1 + /Name /F1 + /BaseFont /Helvetica + /Encoding /WinAnsiEncoding +>> +endobj + +7 0 obj +endobj + +xref +0 8 +0000000000 65535 f +0000000009 00000 n +0000000074 00000 n +0000000146 00000 n +0000000318 00000 n +0000000414 00000 n +0000000449 00000 n +0000000567 00000 n +trailer << + /Size 8 + /Root 1 0 R +>> +startxref +583 +%%EOF