From a94a729fee946947db7a056f02b326dfce681128 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Fri, 28 Jul 2017 18:02:39 -0400 Subject: Explicitly check root dictionary type Very badly corrupted files may not have a retrievable root dictionary. Handle that as a special case so that a more helpful error message can be provided. --- libqpdf/QPDF.cc | 9 ++++++++- qpdf/qtest/qpdf/bad35-recover.out | 2 +- qpdf/qtest/qpdf/bad35.out | 2 +- qpdf/qtest/qpdf/issue-100.out | 2 +- qpdf/qtest/qpdf/issue-118.out | 2 +- qpdf/qtest/qpdf/issue-99.out | 2 +- qpdf/qtest/qpdf/issue-99b.out | 2 +- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index b5c1212c..4d5bf67f 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -2028,7 +2028,14 @@ QPDF::getTrailer() QPDFObjectHandle QPDF::getRoot() { - return this->trailer.getKey("/Root"); + QPDFObjectHandle root = this->trailer.getKey("/Root"); + if (! root.isDictionary()) + { + throw QPDFExc(qpdf_e_damaged_pdf, file->getName(), + "", file->getLastOffset(), + "unable to find /Root dictionary"); + } + return root; } void diff --git a/qpdf/qtest/qpdf/bad35-recover.out b/qpdf/qtest/qpdf/bad35-recover.out index db7ff5d9..dec903ec 100644 --- a/qpdf/qtest/qpdf/bad35-recover.out +++ b/qpdf/qtest/qpdf/bad35-recover.out @@ -1,2 +1,2 @@ WARNING: bad35.pdf (object 1 0, file position 521): supposed object stream 1 has wrong type -operation for Dictionary object attempted on object of wrong type +bad35.pdf (file position 521): unable to find /Root dictionary diff --git a/qpdf/qtest/qpdf/bad35.out b/qpdf/qtest/qpdf/bad35.out index db7ff5d9..dec903ec 100644 --- a/qpdf/qtest/qpdf/bad35.out +++ b/qpdf/qtest/qpdf/bad35.out @@ -1,2 +1,2 @@ WARNING: bad35.pdf (object 1 0, file position 521): supposed object stream 1 has wrong type -operation for Dictionary object attempted on object of wrong type +bad35.pdf (file position 521): unable to find /Root dictionary diff --git a/qpdf/qtest/qpdf/issue-100.out b/qpdf/qtest/qpdf/issue-100.out index 5ff2dc52..1a04b373 100644 --- a/qpdf/qtest/qpdf/issue-100.out +++ b/qpdf/qtest/qpdf/issue-100.out @@ -12,4 +12,4 @@ WARNING: issue-100.pdf (object 5 0, file position 418): /Length key in stream di WARNING: issue-100.pdf (object 5 0, file position 489): attempting to recover stream length WARNING: issue-100.pdf (trailer, file position 953): expected dictionary key but found non-name object; inserting key /QPDFFake1 WARNING: issue-100.pdf (trailer, file position 953): dictionary ended prematurely; using null as value for last key -operation for Dictionary object attempted on object of wrong type +issue-100.pdf (file position 1138): unable to find /Root dictionary diff --git a/qpdf/qtest/qpdf/issue-118.out b/qpdf/qtest/qpdf/issue-118.out index a71c4ba9..58b0778c 100644 --- a/qpdf/qtest/qpdf/issue-118.out +++ b/qpdf/qtest/qpdf/issue-118.out @@ -1,3 +1,3 @@ WARNING: issue-118.pdf (file position 732): loop detected resolving object 2 0 WARNING: issue-118.pdf (xref stream: object 8 0, file position 732): supposed object stream 2 is not a stream -operation for Dictionary object attempted on object of wrong type +issue-118.pdf (file position 732): unable to find /Root dictionary diff --git a/qpdf/qtest/qpdf/issue-99.out b/qpdf/qtest/qpdf/issue-99.out index 89d6e174..eb20da6e 100644 --- a/qpdf/qtest/qpdf/issue-99.out +++ b/qpdf/qtest/qpdf/issue-99.out @@ -1,4 +1,4 @@ WARNING: issue-99.pdf: file is damaged WARNING: issue-99.pdf (file position 3526): xref not found WARNING: issue-99.pdf: Attempting to reconstruct cross-reference table -operation for Dictionary object attempted on object of wrong type +issue-99.pdf (file position 4793): unable to find /Root dictionary diff --git a/qpdf/qtest/qpdf/issue-99b.out b/qpdf/qtest/qpdf/issue-99b.out index 355701be..8f012b1a 100644 --- a/qpdf/qtest/qpdf/issue-99b.out +++ b/qpdf/qtest/qpdf/issue-99b.out @@ -2,4 +2,4 @@ WARNING: issue-99b.pdf: file is damaged WARNING: issue-99b.pdf (object 1 0, file position 9): object with ID 0 WARNING: issue-99b.pdf: Attempting to reconstruct cross-reference table WARNING: issue-99b.pdf: object 1 0 not found in file after regenerating cross reference table -operation for Dictionary object attempted on object of wrong type +issue-99b.pdf (file position 757): unable to find /Root dictionary -- cgit v1.2.3-54-g00ecf