Commit c1e53f148096c329650068694fbde82f018560bf
1 parent
bfdd26fb
bug fix: more gracefully handle xref stream with too many entries
git-svn-id: svn+q:///qpdf/trunk@747 71b93d88-0707-0410-a8cf-f5a4172ac649
Showing
7 changed files
with
65 additions
and
5 deletions
ChangeLog
| 1 | +2009-10-04 Jay Berkenbilt <ejb@ql.org> | |
| 2 | + | |
| 3 | + * libqpdf/QPDF.cc (processXRefStream): warn and ignore extra xref | |
| 4 | + stream entries when stream is larger than reported size. This | |
| 5 | + used to be a fatal error. (Fixes qpdf-Bugs-2872265.) | |
| 6 | + | |
| 1 | 7 | 2009-09-27 Jay Berkenbilt <ejb@ql.org> |
| 2 | 8 | |
| 3 | 9 | * Add several methods to query permissions controlled by the | ... | ... |
libqpdf/QPDF.cc
| ... | ... | @@ -787,10 +787,18 @@ QPDF::processXRefStream(off_t xref_offset, QPDFObjectHandle& xref_obj) |
| 787 | 787 | |
| 788 | 788 | if (expected_size != actual_size) |
| 789 | 789 | { |
| 790 | - throw QPDFExc(this->file.getName(), xref_offset, | |
| 791 | - "Cross-reference stream data has the wrong size;" | |
| 792 | - " expected = " + QUtil::int_to_string(expected_size) + | |
| 793 | - "; actual = " + QUtil::int_to_string(actual_size)); | |
| 790 | + QPDFExc x(this->file.getName(), xref_offset, | |
| 791 | + "Cross-reference stream data has the wrong size;" | |
| 792 | + " expected = " + QUtil::int_to_string(expected_size) + | |
| 793 | + "; actual = " + QUtil::int_to_string(actual_size)); | |
| 794 | + if (expected_size > actual_size) | |
| 795 | + { | |
| 796 | + throw x; | |
| 797 | + } | |
| 798 | + else | |
| 799 | + { | |
| 800 | + warn(x); | |
| 801 | + } | |
| 794 | 802 | } |
| 795 | 803 | |
| 796 | 804 | int cur_chunk = 0; | ... | ... |
qpdf/qtest/qpdf.test
| ... | ... | @@ -81,7 +81,7 @@ flush_tiff_cache(); |
| 81 | 81 | show_ntests(); |
| 82 | 82 | # ---------- |
| 83 | 83 | $td->notify("--- Miscellaneous Tests ---"); |
| 84 | -$n_tests += 4; | |
| 84 | +$n_tests += 7; | |
| 85 | 85 | |
| 86 | 86 | foreach (my $i = 1; $i <= 3; ++$i) |
| 87 | 87 | { |
| ... | ... | @@ -98,6 +98,23 @@ $td->runtest("unknown decode parameters", |
| 98 | 98 | $td->EXIT_STATUS => 0}, |
| 99 | 99 | $td->NORMALIZE_NEWLINES); |
| 100 | 100 | |
| 101 | +# Handle xref stream with more entries than reported (bug 2872265) | |
| 102 | +$td->runtest("xref with short size", | |
| 103 | + {$td->COMMAND => "qpdf --show-xref xref-with-short-size.pdf"}, | |
| 104 | + {$td->FILE => "xref-with-short-size.out", | |
| 105 | + $td->EXIT_STATUS => 3}, | |
| 106 | + $td->NORMALIZE_NEWLINES); | |
| 107 | +$td->runtest("recover xref with short size", | |
| 108 | + {$td->COMMAND => "qpdf xref-with-short-size.pdf a.pdf"}, | |
| 109 | + {$td->FILE => "xref-with-short-size-recover.out", | |
| 110 | + $td->EXIT_STATUS => 3}, | |
| 111 | + $td->NORMALIZE_NEWLINES); | |
| 112 | +$td->runtest("show new xref stream", | |
| 113 | + {$td->COMMAND => "qpdf --show-xref a.pdf"}, | |
| 114 | + {$td->FILE => "xref-with-short-size-new.out", | |
| 115 | + $td->EXIT_STATUS => 0}, | |
| 116 | + $td->NORMALIZE_NEWLINES); | |
| 117 | + | |
| 101 | 118 | show_ntests(); |
| 102 | 119 | # ---------- |
| 103 | 120 | $td->notify("--- Error Condition Tests ---"); | ... | ... |
qpdf/qtest/qpdf/xref-with-short-size-new.out
0 → 100644
| 1 | +1/0: uncompressed; offset = 15 | |
| 2 | +2/0: compressed; stream = 1, index = 0 | |
| 3 | +3/0: compressed; stream = 1, index = 1 | |
| 4 | +4/0: compressed; stream = 1, index = 2 | |
| 5 | +5/0: compressed; stream = 1, index = 3 | |
| 6 | +6/0: compressed; stream = 1, index = 4 | |
| 7 | +7/0: compressed; stream = 1, index = 5 | |
| 8 | +8/0: compressed; stream = 1, index = 6 | |
| 9 | +9/0: compressed; stream = 1, index = 7 | |
| 10 | +10/0: compressed; stream = 1, index = 8 | |
| 11 | +11/0: uncompressed; offset = 674 | |
| 12 | +12/0: uncompressed; offset = 801 | |
| 13 | +13/0: uncompressed; offset = 16194 | ... | ... |
qpdf/qtest/qpdf/xref-with-short-size-recover.out
0 → 100644
qpdf/qtest/qpdf/xref-with-short-size.out
0 → 100644
| 1 | +WARNING: xref-with-short-size.pdf: offset 16227: Cross-reference stream data has the wrong size; expected = 52; actual = 56 | |
| 2 | +1/0: compressed; stream = 5, index = 1 | |
| 3 | +2/0: compressed; stream = 5, index = 0 | |
| 4 | +3/0: uncompressed; offset = 15 | |
| 5 | +4/0: compressed; stream = 5, index = 5 | |
| 6 | +5/0: uncompressed; offset = 15548 | |
| 7 | +6/0: compressed; stream = 5, index = 6 | |
| 8 | +7/0: compressed; stream = 5, index = 4 | |
| 9 | +8/0: compressed; stream = 5, index = 2 | |
| 10 | +9/0: uncompressed; offset = 150 | |
| 11 | +10/0: compressed; stream = 5, index = 3 | |
| 12 | +11/0: compressed; stream = 5, index = 7 | |
| 13 | +12/0: compressed; stream = 5, index = 8 | |
| 14 | +qpdf: operation succeeded with warnings; resulting file may have some problems | ... | ... |
qpdf/qtest/qpdf/xref-with-short-size.pdf
0 → 100644
No preview for this file type