diff --git a/ChangeLog b/ChangeLog index 264b0826..8732f22e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2017-07-29 Jay Berkenbilt + * When recovering stream length, indicate the recovered length. + Fixes #44. + * Add --newline-before-endstream command-line option and setNewlineBeforeEndstream method to QPDFWriter. This forces qpdf to always add a newline before the endstream keyword. It is a diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index bda87f01..a5f956b8 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -1316,6 +1316,13 @@ QPDF::recoverStreamLength(PointerHolder input, this->last_object_description, stream_offset, "unable to recover stream data; treating stream as empty")); } + else + { + warn(QPDFExc(qpdf_e_damaged_pdf, input->getName(), + this->last_object_description, stream_offset, + "recovered stream length: " + + QUtil::int_to_string(length))); + } QTC::TC("qpdf", "QPDF recovered stream length"); return length; diff --git a/qpdf/qtest/qpdf/bad22-recover.out b/qpdf/qtest/qpdf/bad22-recover.out index b2b59fbf..366eb7cb 100644 --- a/qpdf/qtest/qpdf/bad22-recover.out +++ b/qpdf/qtest/qpdf/bad22-recover.out @@ -1,5 +1,6 @@ WARNING: bad22.pdf (object 4 0, file position 314): stream dictionary lacks /Length key WARNING: bad22.pdf (object 4 0, file position 341): attempting to recover stream length +WARNING: bad22.pdf (object 4 0, file position 341): recovered stream length: 44 /QTest is indirect and has type stream (10) /QTest is a stream. Dictionary: << /Qength 44 >> Raw stream data: diff --git a/qpdf/qtest/qpdf/bad23-recover.out b/qpdf/qtest/qpdf/bad23-recover.out index 348a6601..52fa2ee4 100644 --- a/qpdf/qtest/qpdf/bad23-recover.out +++ b/qpdf/qtest/qpdf/bad23-recover.out @@ -1,5 +1,6 @@ WARNING: bad23.pdf (object 4 0, file position 314): /Length key in stream dictionary is not an integer WARNING: bad23.pdf (object 4 0, file position 341): attempting to recover stream length +WARNING: bad23.pdf (object 4 0, file position 341): recovered stream length: 44 /QTest is indirect and has type stream (10) /QTest is a stream. Dictionary: << /Length () >> Raw stream data: diff --git a/qpdf/qtest/qpdf/heifer.out b/qpdf/qtest/qpdf/heifer.out index 867374e6..cd02c232 100644 --- a/qpdf/qtest/qpdf/heifer.out +++ b/qpdf/qtest/qpdf/heifer.out @@ -3,4 +3,5 @@ WARNING: heifer.pdf (file position 92741): xref not found WARNING: heifer.pdf: Attempting to reconstruct cross-reference table WARNING: heifer.pdf (object 2 0, file position 2165): expected endstream WARNING: heifer.pdf (object 2 0, file position 51): attempting to recover stream length +WARNING: heifer.pdf (object 2 0, file position 51): recovered stream length: 2249 qpdf: operation succeeded with warnings; resulting file may have some problems diff --git a/qpdf/qtest/qpdf/issue-100.out b/qpdf/qtest/qpdf/issue-100.out index 1a04b373..dfbe117f 100644 --- a/qpdf/qtest/qpdf/issue-100.out +++ b/qpdf/qtest/qpdf/issue-100.out @@ -10,6 +10,7 @@ WARNING: issue-100.pdf (file position 304): unknown token while reading object; WARNING: issue-100.pdf (file position 308): unexpected ) WARNING: issue-100.pdf (object 5 0, file position 418): /Length key in stream dictionary is not an integer WARNING: issue-100.pdf (object 5 0, file position 489): attempting to recover stream length +WARNING: issue-100.pdf (object 5 0, file position 489): recovered stream length: 12 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 issue-100.pdf (file position 1138): unable to find /Root dictionary diff --git a/qpdf/qtest/qpdf/issue-101.out b/qpdf/qtest/qpdf/issue-101.out index 9e7be113..95697276 100644 --- a/qpdf/qtest/qpdf/issue-101.out +++ b/qpdf/qtest/qpdf/issue-101.out @@ -5,8 +5,10 @@ WARNING: issue-101.pdf (file position 1242): expected dictionary key but found n WARNING: issue-101.pdf (file position 1242): dictionary ended prematurely; using null as value for last key WARNING: issue-101.pdf (object 5 0, file position 1438): /Length key in stream dictionary is not an integer WARNING: issue-101.pdf (object 5 0, file position 1509): attempting to recover stream length +WARNING: issue-101.pdf (object 5 0, file position 1509): recovered stream length: 205 WARNING: issue-101.pdf (trailer, file position 2026): /Length key in stream dictionary is not an integer WARNING: issue-101.pdf (trailer, file position 2097): attempting to recover stream length +WARNING: issue-101.pdf (trailer, file position 2097): recovered stream length: 709 WARNING: issue-101.pdf (trailer, file position 2928): unknown token while reading object; treating as string WARNING: issue-101.pdf (trailer, file position 2930): unknown token while reading object; treating as string WARNING: issue-101.pdf (trailer, file position 2928): expected dictionary key but found non-name object; inserting key /QPDFFake1 @@ -14,10 +16,13 @@ WARNING: issue-101.pdf (trailer, file position 2928): expected dictionary key bu WARNING: issue-101.pdf (trailer, file position 2928): expected dictionary key but found non-name object; inserting key /QPDFFake3 WARNING: issue-101.pdf (trailer, file position 2925): /Length key in stream dictionary is not an integer WARNING: issue-101.pdf (trailer, file position 2996): attempting to recover stream length +WARNING: issue-101.pdf (trailer, file position 2996): recovered stream length: 12 WARNING: issue-101.pdf (trailer, file position 3339): /Length key in stream dictionary is not an integer WARNING: issue-101.pdf (trailer, file position 3410): attempting to recover stream length +WARNING: issue-101.pdf (trailer, file position 3410): recovered stream length: 12 WARNING: issue-101.pdf (trailer, file position 3560): /Length key in stream dictionary is not an integer WARNING: issue-101.pdf (trailer, file position 3631): attempting to recover stream length +WARNING: issue-101.pdf (trailer, file position 3631): recovered stream length: 167 WARNING: issue-101.pdf (trailer, file position 4113): /Length key in stream dictionary is not an integer WARNING: issue-101.pdf (trailer, file position 4184): attempting to recover stream length WARNING: issue-101.pdf (trailer, file position 4184): unable to recover stream data; treating stream as empty diff --git a/qpdf/qtest/qpdf/issue-117.out b/qpdf/qtest/qpdf/issue-117.out index 2d6e5edb..8aa05072 100644 --- a/qpdf/qtest/qpdf/issue-117.out +++ b/qpdf/qtest/qpdf/issue-117.out @@ -4,4 +4,5 @@ WARNING: issue-117.pdf: Attempting to reconstruct cross-reference table WARNING: issue-117.pdf (file position 66): loop detected resolving object 2 0 WARNING: issue-117.pdf (object 2 0, file position 22): /Length key in stream dictionary is not an integer WARNING: issue-117.pdf (object 2 0, file position 67): attempting to recover stream length +WARNING: issue-117.pdf (object 2 0, file position 67): recovered stream length: 91 attempt to make a stream into a direct object diff --git a/qpdf/qtest/qpdf/linearization-bounds-1.out b/qpdf/qtest/qpdf/linearization-bounds-1.out index 3ad15197..99025ee5 100644 --- a/qpdf/qtest/qpdf/linearization-bounds-1.out +++ b/qpdf/qtest/qpdf/linearization-bounds-1.out @@ -4,4 +4,5 @@ File is not encrypted File is linearized WARNING: linearization-bounds-1.pdf (linearization hint stream: object 62 0, file position 1001182): EOF while reading token WARNING: linearization-bounds-1.pdf (linearization hint stream: object 62 0, file position 1183): attempting to recover stream length +WARNING: linearization-bounds-1.pdf (linearization hint stream: object 62 0, file position 1183): recovered stream length: 106 linearization-bounds-1.pdf (linearization hint table, file position 1183): /S (shared object) offset is out of bounds diff --git a/qpdf/qtest/qpdf/linearization-bounds-2.out b/qpdf/qtest/qpdf/linearization-bounds-2.out index 4649b1da..f7516fff 100644 --- a/qpdf/qtest/qpdf/linearization-bounds-2.out +++ b/qpdf/qtest/qpdf/linearization-bounds-2.out @@ -4,4 +4,5 @@ File is not encrypted File is linearized WARNING: linearization-bounds-2.pdf (linearization hint stream: object 62 0, file position 1282): expected endstream WARNING: linearization-bounds-2.pdf (linearization hint stream: object 62 0, file position 1183): attempting to recover stream length +WARNING: linearization-bounds-2.pdf (linearization hint stream: object 62 0, file position 1183): recovered stream length: 106 linearization-bounds-2.pdf (linearization hint table, file position 1183): /S (shared object) offset is out of bounds diff --git a/qpdf/qtest/qpdf/linearization-large-vector-alloc.out b/qpdf/qtest/qpdf/linearization-large-vector-alloc.out index 067bbfa1..ddb49d62 100644 --- a/qpdf/qtest/qpdf/linearization-large-vector-alloc.out +++ b/qpdf/qtest/qpdf/linearization-large-vector-alloc.out @@ -4,4 +4,5 @@ File is not encrypted File is linearized WARNING: linearization-large-vector-alloc.pdf (linearization hint stream: object 62 0, file position 1282): expected endstream WARNING: linearization-large-vector-alloc.pdf (linearization hint stream: object 62 0, file position 1183): attempting to recover stream length +WARNING: linearization-large-vector-alloc.pdf (linearization hint stream: object 62 0, file position 1183): recovered stream length: 106 overflow reading bit stream