Commit 9cb220a4c20c62fd5718082050a601f39a554570
Committed by
GitHub
Merge pull request #1504 from m-holger/fuzz
Improve linearization logic to handle invalid thumbnails gracefully a…
Showing
4 changed files
with
116 additions
and
18 deletions
libqpdf/QPDF_linearization.cc
| ... | ... | @@ -1288,24 +1288,20 @@ QPDF::calculateLinearizationData(T const& object_stream_data) |
| 1288 | 1288 | for (size_t i = 0; i < toS(npages); ++i) { |
| 1289 | 1289 | QPDFObjectHandle thumb = pages.at(i).getKey("/Thumb"); |
| 1290 | 1290 | thumb = getUncompressedObject(thumb, object_stream_data); |
| 1291 | - if (!thumb.isNull()) { | |
| 1292 | - // Output the thumbnail itself | |
| 1293 | - QPDFObjGen thumb_og(thumb.getObjGen()); | |
| 1294 | - if (lc_thumbnail_private.contains(thumb_og)) { | |
| 1295 | - lc_thumbnail_private.erase(thumb_og); | |
| 1296 | - m->part9.push_back(thumb); | |
| 1297 | - } else { | |
| 1298 | - // No internal error this time...there's nothing to stop this object from having | |
| 1299 | - // been referred to somewhere else outside of a page's /Thumb, and if it had been, | |
| 1300 | - // there's nothing to prevent it from having been in some set other than | |
| 1301 | - // lc_thumbnail_private. | |
| 1302 | - } | |
| 1303 | - std::set<QPDFObjGen>& ogs = m->obj_user_to_objects[ObjUser(ObjUser::ou_thumb, toI(i))]; | |
| 1304 | - for (auto const& og: ogs) { | |
| 1305 | - if (lc_thumbnail_private.contains(og)) { | |
| 1306 | - lc_thumbnail_private.erase(og); | |
| 1307 | - m->part9.push_back(getObject(og)); | |
| 1308 | - } | |
| 1291 | + QPDFObjGen thumb_og(thumb.getObjGen()); | |
| 1292 | + // Output the thumbnail itself | |
| 1293 | + if (lc_thumbnail_private.erase(thumb_og) && !thumb.isNull()) { | |
| 1294 | + m->part9.emplace_back(thumb); | |
| 1295 | + } else { | |
| 1296 | + // No internal error this time...there's nothing to stop this object from having | |
| 1297 | + // been referred to somewhere else outside of a page's /Thumb, and if it had been, | |
| 1298 | + // there's nothing to prevent it from having been in some set other than | |
| 1299 | + // lc_thumbnail_private. | |
| 1300 | + } | |
| 1301 | + std::set<QPDFObjGen>& ogs = m->obj_user_to_objects[ObjUser(ObjUser::ou_thumb, toI(i))]; | |
| 1302 | + for (auto const& og: ogs) { | |
| 1303 | + if (lc_thumbnail_private.erase(og)) { | |
| 1304 | + m->part9.emplace_back(getObject(og)); | |
| 1309 | 1305 | } |
| 1310 | 1306 | } |
| 1311 | 1307 | } | ... | ... |
qpdf/qtest/qpdf/issue-1503.out
0 → 100644
| 1 | +WARNING: issue-1503.pdf: can't find PDF header | |
| 2 | +WARNING: issue-1503.pdf: file is damaged | |
| 3 | +WARNING: issue-1503.pdf: can't find startxref | |
| 4 | +WARNING: issue-1503.pdf: Attempting to reconstruct cross-reference table | |
| 5 | +WARNING: issue-1503.pdf (object 31 0, offset 813): unknown token while reading object; treating as null | |
| 6 | +WARNING: issue-1503.pdf (object 31 0, offset 851): unknown token while reading object; treating as null | |
| 7 | +WARNING: issue-1503.pdf (object 31 0, offset 856): unknown token while reading object; treating as null | |
| 8 | +WARNING: issue-1503.pdf (object 31 0, offset 861): unexpected 'endobj' or 'endstream' while reading object; giving up on reading object | |
| 9 | +WARNING: issue-1503.pdf (object 31 0, offset 871): expected endobj | |
| 10 | +WARNING: issue-1503.pdf (object 38 0, offset 1126): unexpected 'endobj' or 'endstream' while reading object; giving up on reading object | |
| 11 | +WARNING: issue-1503.pdf (object 38 0, offset 1133): expected endobj | |
| 12 | +WARNING: issue-1503.pdf (object 40 0, offset 1195): unexpected array close token; giving up on reading object | |
| 13 | +WARNING: issue-1503.pdf (object 40 0, offset 1198): expected endobj | |
| 14 | +WARNING: issue-1503.pdf (object 41 0, offset 1359): stream dictionary lacks /Length key | |
| 15 | +WARNING: issue-1503.pdf (object 41 0, offset 1411): attempting to recover stream length | |
| 16 | +WARNING: issue-1503.pdf (object 41 0, offset 1411): recovered stream length: 54 | |
| 17 | +WARNING: issue-1503.pdf (object 44 0, offset 1744): unknown token while reading object; treating as null | |
| 18 | +WARNING: issue-1503.pdf (object 44 0, offset 1767): unknown token while reading object; treating as null | |
| 19 | +WARNING: issue-1503.pdf (object 44 0, offset 1775): unknown token while reading object; treating as null | |
| 20 | +WARNING: issue-1503.pdf (object 44 0, offset 1779): unknown token while reading object; treating as null | |
| 21 | +WARNING: issue-1503.pdf (object 44 0, offset 1814): name with stray # will not work with PDF >= 1.2 | |
| 22 | +WARNING: issue-1503.pdf (object 44 0, offset 1821): unknown token while reading object; treating as null | |
| 23 | +WARNING: issue-1503.pdf (object 44 0, offset 1826): unknown token while reading object; treating as null | |
| 24 | +WARNING: issue-1503.pdf (object 44 0, offset 1826): too many errors; giving up on reading object | |
| 25 | +WARNING: issue-1503.pdf (object 44 0, offset 1829): expected endobj | |
| 26 | +WARNING: issue-1503.pdf (object 46 0, offset 1923): unexpected array close token; giving up on reading object | |
| 27 | +WARNING: issue-1503.pdf (object 46 0, offset 1926): expected endobj | |
| 28 | +WARNING: issue-1503.pdf (object 47 0, offset 2087): stream dictionary lacks /Length key | |
| 29 | +WARNING: issue-1503.pdf (object 47 0, offset 2139): attempting to recover stream length | |
| 30 | +WARNING: issue-1503.pdf (object 47 0, offset 2139): recovered stream length: 54 | |
| 31 | +WARNING: issue-1503.pdf (object 49 0, offset 2256): unknown token while reading object; treating as null | |
| 32 | +WARNING: issue-1503.pdf (object 49 0, offset 2271): unknown token while reading object; treating as null | |
| 33 | +WARNING: issue-1503.pdf (object 49 0, offset 2241): expected dictionary keys but found non-name objects; ignoring | |
| 34 | +WARNING: issue-1503.pdf (object 50 0, offset 2483): unknown token while reading object; treating as null | |
| 35 | +WARNING: issue-1503.pdf (object 50 0, offset 2453): expected dictionary keys but found non-name objects; ignoring | |
| 36 | +WARNING: issue-1503.pdf (object 50 0, offset 2450): stream dictionary lacks /Length key | |
| 37 | +WARNING: issue-1503.pdf (object 50 0, offset 2530): attempting to recover stream length | |
| 38 | +WARNING: issue-1503.pdf (object 50 0, offset 2530): unable to recover stream data; treating stream as empty | |
| 39 | +WARNING: issue-1503.pdf (object 114 0, offset 2693): unknown token while reading object; treating as null | |
| 40 | +WARNING: issue-1503.pdf (object 114 0, offset 2697): unknown token while reading object; treating as null | |
| 41 | +WARNING: issue-1503.pdf (object 114 0, offset 2652): expected dictionary keys but found non-name objects; ignoring | |
| 42 | +WARNING: issue-1503.pdf (object 114 0, offset 2649): stream dictionary lacks /Length key | |
| 43 | +WARNING: issue-1503.pdf (object 114 0, offset 2783): attempting to recover stream length | |
| 44 | +WARNING: issue-1503.pdf (object 114 0, offset 2783): recovered stream length: 84 | |
| 45 | +WARNING: issue-1503.pdf (object 116 0, offset 2927): unknown token while reading object; treating as null | |
| 46 | +WARNING: issue-1503.pdf (object 116 0, offset 2914): stream dictionary lacks /Length key | |
| 47 | +WARNING: issue-1503.pdf (object 116 0, offset 3101): attempting to recover stream length | |
| 48 | +WARNING: issue-1503.pdf (object 116 0, offset 3101): recovered stream length: 84 | |
| 49 | +WARNING: issue-1503.pdf (object 118 0, offset 3271): unknown token while reading object; treating as null | |
| 50 | +WARNING: issue-1503.pdf (object 118 0, offset 3235): expected dictionary keys but found non-name objects; ignoring | |
| 51 | +WARNING: issue-1503.pdf (object 118 0, offset 3232): /Length key in stream dictionary is not an integer | |
| 52 | +WARNING: issue-1503.pdf (object 118 0, offset 3370): attempting to recover stream length | |
| 53 | +WARNING: issue-1503.pdf (object 118 0, offset 3370): recovered stream length: 102 | |
| 54 | +WARNING: issue-1503.pdf (object 120 0, offset 3519): stream dictionary lacks /Length key | |
| 55 | +WARNING: issue-1503.pdf (object 120 0, offset 3653): attempting to recover stream length | |
| 56 | +WARNING: issue-1503.pdf (object 120 0, offset 3653): unable to recover stream data; treating stream as empty | |
| 57 | +WARNING: issue-1503.pdf (object 122 0, offset 3723): expected endobj | |
| 58 | +WARNING: issue-1503.pdf (object 151 0, offset 3836): unknown token while reading object; treating as null | |
| 59 | +WARNING: issue-1503.pdf (object 151 0, offset 3958): unknown token while reading object; treating as null | |
| 60 | +WARNING: issue-1503.pdf (object 152 0, offset 4088): parse error while reading object | |
| 61 | +WARNING: issue-1503.pdf (object 152 0, offset 4088): unexpected EOF | |
| 62 | +WARNING: issue-1503.pdf (object 152 0, offset 4088): expected endobj | |
| 63 | +WARNING: issue-1503.pdf (object 152 0, offset 4088): EOF after endobj | |
| 64 | +WARNING: issue-1503.pdf (object 155 0, offset 162): unknown token while reading object; treating as null | |
| 65 | +WARNING: issue-1503.pdf (object 155 0, offset 342): unknown token while reading object; treating as null | |
| 66 | +WARNING: issue-1503.pdf (object 155 0, offset 345): unknown token while reading object; treating as null | |
| 67 | +WARNING: issue-1503.pdf (object 155 0, offset 334): expected dictionary keys but found non-name objects; ignoring | |
| 68 | +WARNING: issue-1503.pdf (object 155 0, offset 152): expected dictionary keys but found non-name objects; ignoring | |
| 69 | +WARNING: issue-1503.pdf (object 155 0, offset 405): unknown token while reading object; treating as null | |
| 70 | +WARNING: issue-1503.pdf (object 155 0, offset 479): unknown token while reading object; treating as null | |
| 71 | +WARNING: issue-1503.pdf (object 155 0, offset 485): unknown token while reading object; treating as null | |
| 72 | +WARNING: issue-1503.pdf (object 155 0, offset 136): expected dictionary keys but found non-name objects; ignoring | |
| 73 | +WARNING: issue-1503.pdf (object 173 0, offset 574): expected endobj | |
| 74 | +WARNING: issue-1503.pdf: unable to find trailer dictionary while recovering damaged file | |
| 75 | +WARNING: object 157 0: Pages tree includes non-dictionary object; ignoring | |
| 76 | +WARNING: issue-1503.pdf, object 151 0 at offset 3831: Pages tree includes non-dictionary object; ignoring | |
| 77 | +WARNING: issue-1503.pdf, object 151 0 at offset 3834: Pages tree includes non-dictionary object; ignoring | |
| 78 | +Pages tree includes non-dictionary object; ignoring | |
| 79 | +WARNING: object 22 0: Pages tree includes non-dictionary object; ignoring | |
| 80 | +WARNING: object 25 0: Pages tree includes non-dictionary object; ignoring | |
| 81 | +WARNING: object 28 0: Pages tree includes non-dictionary object; ignoring | |
| 82 | +WARNING: object 31 0: Pages tree includes non-dictionary object; ignoring | |
| 83 | +WARNING: object 34 0: Pages tree includes non-dictionary object; ignoring | |
| 84 | +WARNING: object 37 0: Pages tree includes non-dictionary object; ignoring | |
| 85 | +WARNING: object 40 0: Pages tree includes non-dictionary object; ignoring | |
| 86 | +WARNING: object 46 0: Pages tree includes non-dictionary object; ignoring | |
| 87 | +WARNING: issue-1503.pdf, object 49 0 at offset 2241: kid 13 (from 0) MediaBox is undefined; setting to letter / ANSI A | |
| 88 | +WARNING: object 52 0: Pages tree includes non-dictionary object; ignoring | |
| 89 | +WARNING: object 55 0: Pages tree includes non-dictionary object; ignoring | |
| 90 | +WARNING: object 58 0: Pages tree includes non-dictionary object; ignoring | |
| 91 | +WARNING: object 61 0: Pages tree includes non-dictionary object; ignoring | |
| 92 | +WARNING: object 64 0: Pages tree includes non-dictionary object; ignoring | |
| 93 | +WARNING: object 67 0: Pages tree includes non-dictionary object; ignoring | |
| 94 | +WARNING: issue-1503.pdf, object 151 0 at offset 3953: Pages tree includes non-dictionary object; ignoring | |
| 95 | +Pages tree includes non-dictionary object; ignoring | |
| 96 | +WARNING: object 73 0: Pages tree includes non-dictionary object; ignoring | |
| 97 | +WARNING: object 76 0: Pages tree includes non-dictionary object; ignoring | |
| 98 | +WARNING: object 79 0: Pages tree includes non-dictionary object; ignoring | |
| 99 | +WARNING: object 82 0: Pages tree includes non-dictionary object; ignoring | |
| 100 | +WARNING: object 85 0: Pages tree includes non-dictionary object; ignoring | |
| 101 | +qpdf: operation succeeded with warnings; resulting file may have some problems | ... | ... |
qpdf/qtest/qpdf/issue-1503.pdf
0 → 100644
No preview for this file type
qpdf/qtest/specific-bugs.test
| ... | ... | @@ -38,6 +38,7 @@ my @bug_tests = ( |
| 38 | 38 | ["263", "empty xref stream", 2], |
| 39 | 39 | ["335a", "ozz-fuzz-12152", 2], |
| 40 | 40 | ["335b", "ozz-fuzz-14845", 2], |
| 41 | + ["1503", "linearize with bad outlines", 3, "--linearize"], | |
| 41 | 42 | ["fuzz-16214", "stream in object stream", 3, "--preserve-unreferenced"], |
| 42 | 43 | # When adding to this list, consider adding to CORPUS_FROM_TEST in |
| 43 | 44 | # fuzz/CMakeLists.txt and updating the count in | ... | ... |