Commit 8a9cfd2605dc6754d92b7b0ab849e082b77a78ae
1 parent
2d0885bc
Handle direct page objects (fixes #164)
Showing
7 changed files
with
144 additions
and
2 deletions
ChangeLog
| 1 | +2019-01-29 Jay Berkenbilt <ejb@ql.org> | ||
| 2 | + | ||
| 3 | + * Handle files with direct page objects, which is not allowed by | ||
| 4 | + the PDF spec but has been seen in the wild. Fixes #164. | ||
| 5 | + | ||
| 1 | 2019-01-28 Jay Berkenbilt <ejb@ql.org> | 6 | 2019-01-28 Jay Berkenbilt <ejb@ql.org> |
| 2 | 7 | ||
| 3 | * Bug fix: when using --stream-data=compress, object streams and | 8 | * Bug fix: when using --stream-data=compress, object streams and |
libqpdf/QPDF_pages.cc
| @@ -105,7 +105,13 @@ QPDF::getAllPagesInternal3(QPDFObjectHandle cur_pages, | @@ -105,7 +105,13 @@ QPDF::getAllPagesInternal3(QPDFObjectHandle cur_pages, | ||
| 105 | for (int i = 0; i < n; ++i) | 105 | for (int i = 0; i < n; ++i) |
| 106 | { | 106 | { |
| 107 | QPDFObjectHandle kid = kids.getArrayItem(i); | 107 | QPDFObjectHandle kid = kids.getArrayItem(i); |
| 108 | - if (seen.count(kid.getObjGen())) | 108 | + if (! kid.isIndirect()) |
| 109 | + { | ||
| 110 | + QTC::TC("qpdf", "QPDF handle direct page object"); | ||
| 111 | + kid = makeIndirectObject(kid); | ||
| 112 | + kids.setArrayItem(i, kid); | ||
| 113 | + } | ||
| 114 | + else if (seen.count(kid.getObjGen())) | ||
| 109 | { | 115 | { |
| 110 | // Make a copy of the page. This does the same as | 116 | // Make a copy of the page. This does the same as |
| 111 | // shallowCopyPage in QPDFPageObjectHelper. | 117 | // shallowCopyPage in QPDFPageObjectHelper. |
qpdf/qpdf.testcov
| @@ -429,3 +429,4 @@ QPDFPageObjectHelper non-trivial inheritance 0 | @@ -429,3 +429,4 @@ QPDFPageObjectHelper non-trivial inheritance 0 | ||
| 429 | QPDFPageObjectHelper copy shared attribute 0 | 429 | QPDFPageObjectHelper copy shared attribute 0 |
| 430 | qpdf from_nr from repeat_nr 0 | 430 | qpdf from_nr from repeat_nr 0 |
| 431 | QPDF resolve duplicated page object 0 | 431 | QPDF resolve duplicated page object 0 |
| 432 | +QPDF handle direct page object 0 |
qpdf/qtest/qpdf.test
| @@ -2461,7 +2461,7 @@ for (my $n = 16; $n <= 19; ++$n) | @@ -2461,7 +2461,7 @@ for (my $n = 16; $n <= 19; ++$n) | ||
| 2461 | show_ntests(); | 2461 | show_ntests(); |
| 2462 | # ---------- | 2462 | # ---------- |
| 2463 | $td->notify("--- Specific File Tests ---"); | 2463 | $td->notify("--- Specific File Tests ---"); |
| 2464 | -$n_tests += 4; | 2464 | +$n_tests += 7; |
| 2465 | 2465 | ||
| 2466 | # Special PDF files that caused problems at some point | 2466 | # Special PDF files that caused problems at some point |
| 2467 | 2467 | ||
| @@ -2482,6 +2482,19 @@ $td->runtest("compress objstm and xref", | @@ -2482,6 +2482,19 @@ $td->runtest("compress objstm and xref", | ||
| 2482 | $td->runtest("check output", | 2482 | $td->runtest("check output", |
| 2483 | {$td->FILE => "a.pdf"}, | 2483 | {$td->FILE => "a.pdf"}, |
| 2484 | {$td->FILE => "compress-objstm-xref.pdf"}); | 2484 | {$td->FILE => "compress-objstm-xref.pdf"}); |
| 2485 | +$td->runtest("direct pages", | ||
| 2486 | + {$td->COMMAND => | ||
| 2487 | + "qpdf --static-id direct-pages.pdf --pages . -- a.pdf"}, | ||
| 2488 | + {$td->STRING => "", $td->EXIT_STATUS => 0}, | ||
| 2489 | + $td->NORMALIZE_NEWLINES); | ||
| 2490 | +$td->runtest("check output", | ||
| 2491 | + {$td->FILE => "a.pdf"}, | ||
| 2492 | + {$td->FILE => "direct-pages-fixed.pdf"}); | ||
| 2493 | +$td->runtest("show direct pages", | ||
| 2494 | + {$td->COMMAND => | ||
| 2495 | + "qpdf --show-pages direct-pages.pdf"}, | ||
| 2496 | + {$td->FILE => "direct-pages.out", $td->EXIT_STATUS => 0}, | ||
| 2497 | + $td->NORMALIZE_NEWLINES); | ||
| 2485 | 2498 | ||
| 2486 | show_ntests(); | 2499 | show_ntests(); |
| 2487 | # ---------- | 2500 | # ---------- |
qpdf/qtest/qpdf/direct-pages-fixed.pdf
0 → 100644
No preview for this file type
qpdf/qtest/qpdf/direct-pages.out
0 → 100644
qpdf/qtest/qpdf/direct-pages.pdf
0 → 100644
| 1 | +%PDF-1.3 | ||
| 2 | +%¿÷¢þ | ||
| 3 | +%QDF-1.0 | ||
| 4 | + | ||
| 5 | +%% Original object ID: 1 0 | ||
| 6 | +1 0 obj | ||
| 7 | +<< | ||
| 8 | + /Pages 2 0 R | ||
| 9 | + /Type /Catalog | ||
| 10 | +>> | ||
| 11 | +endobj | ||
| 12 | + | ||
| 13 | +%% Original object ID: 2 0 | ||
| 14 | +2 0 obj | ||
| 15 | +<< | ||
| 16 | + /Count 2 | ||
| 17 | + /Kids [ | ||
| 18 | + << | ||
| 19 | + /Contents 3 0 R | ||
| 20 | + /MediaBox [ | ||
| 21 | + 0 | ||
| 22 | + 0 | ||
| 23 | + 612 | ||
| 24 | + 792 | ||
| 25 | + ] | ||
| 26 | + /Parent 2 0 R | ||
| 27 | + /Resources << | ||
| 28 | + /Font << | ||
| 29 | + /F1 5 0 R | ||
| 30 | + >> | ||
| 31 | + /ProcSet 6 0 R | ||
| 32 | + >> | ||
| 33 | + /Type /Page | ||
| 34 | + >> | ||
| 35 | + << | ||
| 36 | + /Contents 3 0 R | ||
| 37 | + /MediaBox [ | ||
| 38 | + 0 | ||
| 39 | + 0 | ||
| 40 | + 612 | ||
| 41 | + 792 | ||
| 42 | + ] | ||
| 43 | + /Parent 2 0 R | ||
| 44 | + /Resources << | ||
| 45 | + /Font << | ||
| 46 | + /F1 5 0 R | ||
| 47 | + >> | ||
| 48 | + /ProcSet 6 0 R | ||
| 49 | + >> | ||
| 50 | + /Type /Page | ||
| 51 | + >> | ||
| 52 | + ] | ||
| 53 | + /Type /Pages | ||
| 54 | +>> | ||
| 55 | +endobj | ||
| 56 | + | ||
| 57 | +%% Contents for page 2 | ||
| 58 | +%% Original object ID: 4 0 | ||
| 59 | +3 0 obj | ||
| 60 | +<< | ||
| 61 | + /Length 4 0 R | ||
| 62 | +>> | ||
| 63 | +stream | ||
| 64 | +BT | ||
| 65 | + /F1 24 Tf | ||
| 66 | + 72 720 Td | ||
| 67 | + (Potato) Tj | ||
| 68 | +ET | ||
| 69 | +endstream | ||
| 70 | +endobj | ||
| 71 | + | ||
| 72 | +4 0 obj | ||
| 73 | +44 | ||
| 74 | +endobj | ||
| 75 | + | ||
| 76 | +%% Original object ID: 6 0 | ||
| 77 | +5 0 obj | ||
| 78 | +<< | ||
| 79 | + /BaseFont /Helvetica | ||
| 80 | + /Encoding /WinAnsiEncoding | ||
| 81 | + /Name /F1 | ||
| 82 | + /Subtype /Type1 | ||
| 83 | + /Type /Font | ||
| 84 | +>> | ||
| 85 | +endobj | ||
| 86 | + | ||
| 87 | +%% Original object ID: 7 0 | ||
| 88 | +6 0 obj | ||
| 89 | +[ | ||
| 90 | |||
| 91 | + /Text | ||
| 92 | +] | ||
| 93 | +endobj | ||
| 94 | + | ||
| 95 | +xref | ||
| 96 | +0 7 | ||
| 97 | +0000000000 65535 f | ||
| 98 | +0000000052 00000 n | ||
| 99 | +0000000133 00000 n | ||
| 100 | +0000000733 00000 n | ||
| 101 | +0000000832 00000 n | ||
| 102 | +0000000878 00000 n | ||
| 103 | +0000001023 00000 n | ||
| 104 | +trailer << | ||
| 105 | + /Root 1 0 R | ||
| 106 | + /Size 7 | ||
| 107 | + /ID [<1323a5937c577a66735583a93698ce3c><372cbf44f6db88ab60d9263c0f0bd26a>] | ||
| 108 | +>> | ||
| 109 | +startxref | ||
| 110 | +1058 | ||
| 111 | +%%EOF |