Commit 7c148c15cf2bbabc9332997b14ba8a8ff1d80773
Committed by
GitHub
Merge pull request #1595 from m-holger/info
Improve error handling for common PDF anomalies.
Showing
5 changed files
with
22 additions
and
11 deletions
libqpdf/QPDF_objects.cc
| ... | ... | @@ -534,12 +534,20 @@ Objects::read_xref(qpdf_offset_t xref_offset, bool in_stream_recovery) |
| 534 | 534 | if (!m->deleted_objects.empty()) { |
| 535 | 535 | max_obj = std::max(max_obj, *(m->deleted_objects.rbegin())); |
| 536 | 536 | } |
| 537 | - if ((size < 1) || (size - 1 != max_obj)) { | |
| 538 | - warn(damagedPDF( | |
| 539 | - "", | |
| 540 | - -1, | |
| 541 | - ("reported number of objects (" + std::to_string(size) + | |
| 542 | - ") is not one plus the highest object number (" + std::to_string(max_obj) + ")"))); | |
| 537 | + if (size < 1 || (size - 1) != max_obj) { | |
| 538 | + if ((size - 2) == max_obj ){//&& qpdf.getObject(max_obj, 0).isStreamOfType("/XRef")) { | |
| 539 | + warn(damagedPDF( | |
| 540 | + "", | |
| 541 | + -1, | |
| 542 | + "xref entry for the xref stream itself is missing - a common error handled " | |
| 543 | + "correctly by qpdf and most other applications")); | |
| 544 | + } else { | |
| 545 | + warn(damagedPDF( | |
| 546 | + "", | |
| 547 | + -1, | |
| 548 | + ("reported number of objects (" + std::to_string(size) + | |
| 549 | + ") is not one plus the highest object number (" + std::to_string(max_obj) + ")"))); | |
| 550 | + } | |
| 543 | 551 | } |
| 544 | 552 | |
| 545 | 553 | // We no longer need the deleted_objects table, so go ahead and clear it out to make sure we |
| ... | ... | @@ -1475,7 +1483,10 @@ Objects::readObjectAtOffset( |
| 1475 | 1483 | // "0000000000 00000 n", which is not correct, but it won't hurt anything for us to ignore |
| 1476 | 1484 | // these. |
| 1477 | 1485 | if (offset == 0) { |
| 1478 | - warn(damagedPDF(-1, "object has offset 0")); | |
| 1486 | + warn(damagedPDF( | |
| 1487 | + -1, | |
| 1488 | + "object has offset 0 - a common error handled correctly by qpdf and most other " | |
| 1489 | + "applications")); | |
| 1479 | 1490 | return; |
| 1480 | 1491 | } |
| 1481 | 1492 | ... | ... |
qpdf/qtest/qpdf/bad12-recover.out
| 1 | -WARNING: bad12.pdf: reported number of objects (9) is not one plus the highest object number (7) | |
| 1 | +WARNING: bad12.pdf: xref entry for the xref stream itself is missing - a common error handled correctly by qpdf and most other applications | |
| 2 | 2 | WARNING: bad12.pdf (object 2 0, offset 128): expected endobj |
| 3 | 3 | /QTest is implicit |
| 4 | 4 | /QTest is direct and has type null (2) | ... | ... |
qpdf/qtest/qpdf/bad12.out
| 1 | -WARNING: bad12.pdf: reported number of objects (9) is not one plus the highest object number (7) | |
| 1 | +WARNING: bad12.pdf: xref entry for the xref stream itself is missing - a common error handled correctly by qpdf and most other applications | |
| 2 | 2 | WARNING: bad12.pdf (object 2 0, offset 128): expected endobj |
| 3 | 3 | /QTest is implicit |
| 4 | 4 | /QTest is direct and has type null (2) | ... | ... |
qpdf/qtest/qpdf/issue-150.out
| ... | ... | @@ -3,5 +3,5 @@ WARNING: issue-150.pdf (xref stream: object 8 0, offset 56): treating object as |
| 3 | 3 | WARNING: issue-150.pdf: file is damaged |
| 4 | 4 | WARNING: issue-150.pdf (offset 4): xref not found |
| 5 | 5 | WARNING: issue-150.pdf: Attempting to reconstruct cross-reference table |
| 6 | -WARNING: issue-150.pdf (object 8 0): object has offset 0 | |
| 6 | +WARNING: issue-150.pdf (object 8 0): object has offset 0 - a common error handled correctly by qpdf and most other applications | |
| 7 | 7 | qpdf: issue-150.pdf: unable to find trailer dictionary while recovering damaged file | ... | ... |
qpdf/qtest/qpdf/zero-offset.out
| ... | ... | @@ -2,5 +2,5 @@ checking zero-offset.pdf |
| 2 | 2 | PDF Version: 1.3 |
| 3 | 3 | File is not encrypted |
| 4 | 4 | File is not linearized |
| 5 | -WARNING: zero-offset.pdf (object 6 0): object has offset 0 | |
| 5 | +WARNING: zero-offset.pdf (object 6 0): object has offset 0 - a common error handled correctly by qpdf and most other applications | |
| 6 | 6 | qpdf: operation succeeded with warnings | ... | ... |