Commit 57c01ef81ff11b208188bbdedc98b6ce20c786b3
1 parent
bbc2f8ff
In qdf mode, don't write extra XRef streams (fixes #386)
fix-qdf assumes there is exactly one XRef stream and that it is at the end of the file.
Showing
5 changed files
with
34 additions
and
1 deletions
ChangeLog
| 1 | 2020-01-26 Jay Berkenbilt <ejb@ql.org> | 1 | 2020-01-26 Jay Berkenbilt <ejb@ql.org> |
| 2 | 2 | ||
| 3 | + * Bug fix: in qdf mode, do not write out any XRef streams that may | ||
| 4 | + have appeared in the original file. These are usually | ||
| 5 | + unreferenced, but with --preserve-unreferenced, they could be | ||
| 6 | + written out, which breaks fix-qdf's assumption that there is at | ||
| 7 | + most one XRef stream and that it appears at the end of the file. | ||
| 8 | + Fixes #386. | ||
| 9 | + | ||
| 3 | * Bug fix: when externalizing inline images, a colorspace value | 10 | * Bug fix: when externalizing inline images, a colorspace value |
| 4 | that was a lookup key in the page's /Resource -> /ColorSpace | 11 | that was a lookup key in the page's /Resource -> /ColorSpace |
| 5 | dictionary was not properly handled. Fixes #392. | 12 | dictionary was not properly handled. Fixes #392. |
libqpdf/QPDFWriter.cc
| @@ -1241,6 +1241,21 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | @@ -1241,6 +1241,21 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | ||
| 1241 | " another file."); | 1241 | " another file."); |
| 1242 | } | 1242 | } |
| 1243 | 1243 | ||
| 1244 | + if (this->m->qdf_mode && | ||
| 1245 | + object.isStream() && object.getDict().getKey("/Type").isName() && | ||
| 1246 | + (object.getDict().getKey("/Type").getName() == "/XRef")) | ||
| 1247 | + { | ||
| 1248 | + // As a special case, do not output any extraneous XRef | ||
| 1249 | + // streams in QDF mode. Doing so will confuse fix-qdf, | ||
| 1250 | + // which expects to see only one XRef stream at the end of | ||
| 1251 | + // the file. This case can occur when creating a QDF from | ||
| 1252 | + // a file with object streams when preserving unreferenced | ||
| 1253 | + // objects since the old cross reference streams are not | ||
| 1254 | + // actually referenced by object number. | ||
| 1255 | + QTC::TC("qpdf", "QPDFWriter ignore XRef in qdf mode"); | ||
| 1256 | + return; | ||
| 1257 | + } | ||
| 1258 | + | ||
| 1244 | QPDFObjGen og = object.getObjGen(); | 1259 | QPDFObjGen og = object.getObjGen(); |
| 1245 | 1260 | ||
| 1246 | if (this->m->obj_renumber.count(og) == 0) | 1261 | if (this->m->obj_renumber.count(og) == 0) |
qpdf/qpdf.testcov
| @@ -448,3 +448,4 @@ QPDFWriter stream in ostream 0 | @@ -448,3 +448,4 @@ QPDFWriter stream in ostream 0 | ||
| 448 | QPDFObjectHandle duplicate dict key 0 | 448 | QPDFObjectHandle duplicate dict key 0 |
| 449 | QPDFWriter no encryption sig contents 0 | 449 | QPDFWriter no encryption sig contents 0 |
| 450 | QPDFPageObjectHelper colorspace lookup 0 | 450 | QPDFPageObjectHelper colorspace lookup 0 |
| 451 | +QPDFWriter ignore XRef in qdf mode 0 |
qpdf/qtest/qpdf.test
| @@ -2779,7 +2779,7 @@ for (my $n = 16; $n <= 19; ++$n) | @@ -2779,7 +2779,7 @@ for (my $n = 16; $n <= 19; ++$n) | ||
| 2779 | show_ntests(); | 2779 | show_ntests(); |
| 2780 | # ---------- | 2780 | # ---------- |
| 2781 | $td->notify("--- Specific File Tests ---"); | 2781 | $td->notify("--- Specific File Tests ---"); |
| 2782 | -$n_tests += 4; | 2782 | +$n_tests += 7; |
| 2783 | 2783 | ||
| 2784 | # Special PDF files that caused problems at some point | 2784 | # Special PDF files that caused problems at some point |
| 2785 | 2785 | ||
| @@ -2800,6 +2800,16 @@ $td->runtest("compress objstm and xref", | @@ -2800,6 +2800,16 @@ $td->runtest("compress objstm and xref", | ||
| 2800 | $td->runtest("check output", | 2800 | $td->runtest("check output", |
| 2801 | {$td->FILE => "a.pdf"}, | 2801 | {$td->FILE => "a.pdf"}, |
| 2802 | {$td->FILE => "compress-objstm-xref.pdf"}); | 2802 | {$td->FILE => "compress-objstm-xref.pdf"}); |
| 2803 | +$td->runtest("qdf + preserved-unreferenced + xref streams", | ||
| 2804 | + {$td->COMMAND => "qpdf --qdf --preserve-unreferenced" . | ||
| 2805 | + " --static-id compress-objstm-xref.pdf a.pdf"}, | ||
| 2806 | + {$td->STRING => "", $td->EXIT_STATUS => 0}); | ||
| 2807 | +$td->runtest("check output", | ||
| 2808 | + {$td->FILE => "a.pdf"}, | ||
| 2809 | + {$td->FILE => "compress-objstm-xref-qdf.pdf"}); | ||
| 2810 | +$td->runtest("check fix-qdf idempotency", | ||
| 2811 | + {$td->COMMAND => "fix-qdf a.pdf"}, | ||
| 2812 | + {$td->FILE => "a.pdf", $td->EXIT_STATUS => 0}); | ||
| 2803 | 2813 | ||
| 2804 | show_ntests(); | 2814 | show_ntests(); |
| 2805 | # ---------- | 2815 | # ---------- |
qpdf/qtest/qpdf/compress-objstm-xref-qdf.pdf
0 → 100644
No preview for this file type