Commit f256670eba636a9b8344987108110e7b1b4c0a46
1 parent
041397fd
Ignore objects with offset 0
Showing
7 changed files
with
57 additions
and
7 deletions
ChangeLog
| 1 | +2012-11-20 Jay Berkenbilt <ejb@ql.org> | ||
| 2 | + | ||
| 3 | + * Ignore (with warning) non-freed objects in the xref table whose | ||
| 4 | + offset is 0. Some PDF producers (incorrectly) do this. See | ||
| 5 | + https://bugs.linuxfoundation.org/show_bug.cgi?id=1081. | ||
| 6 | + | ||
| 1 | 2012-09-23 Jay Berkenbilt <ejb@ql.org> | 7 | 2012-09-23 Jay Berkenbilt <ejb@ql.org> |
| 2 | 8 | ||
| 3 | * Add public methods QPDF::processInputSource and | 9 | * Add public methods QPDF::processInputSource and |
TODO
| 1 | General | 1 | General |
| 2 | ======= | 2 | ======= |
| 3 | 3 | ||
| 4 | - * See if I can support the encryption format used with /R 5 /V 5, | ||
| 5 | - even though a qpdf-announce subscriber with an adobe.com email | ||
| 6 | - address mentioned that this is deprecated. There is also a new | ||
| 7 | - encryption format coming in a future release, which may be better | ||
| 8 | - to support. As of the qpdf 3.0 release, the specification was not | ||
| 9 | - publicly available yet. | 4 | + * See if I can support the encryption format used with /R 5 /V 5 |
| 5 | + (AESV3), even though a qpdf-announce subscriber with an adobe.com | ||
| 6 | + email address mentioned that this is deprecated. There is also a | ||
| 7 | + new encryption format coming in a future release (PDF 2.0), which | ||
| 8 | + may be better to support. As of the qpdf 3.0 release, the | ||
| 9 | + specification was not publicly available yet. | ||
| 10 | + | ||
| 11 | + AESV3 encryption is supported with PDF 1.7 extension level 3 and is | ||
| 12 | + being deprecated, but there are plenty of files out there. The | ||
| 13 | + encryption format is decribed in adobe_supplement_iso32000.pdf. | ||
| 14 | + Such a file must specify that it uses these extensions in its | ||
| 15 | + document catalog: | ||
| 16 | + | ||
| 17 | + << | ||
| 18 | + /Type /Catalog | ||
| 19 | + /Extensions << | ||
| 20 | + /ADBE << | ||
| 21 | + /BaseVersion /1.7 | ||
| 22 | + /ExtensionLevel 3 | ||
| 23 | + >> | ||
| 24 | + >> | ||
| 25 | + >> | ||
| 26 | + | ||
| 27 | + Possible sha256 implementations: http://sol-biotech.com/code/sha2/, | ||
| 28 | + http://hashlib2plus.sourceforge.net/ | ||
| 10 | 29 | ||
| 11 | * Consider the possibility of doing something locale-aware to support | 30 | * Consider the possibility of doing something locale-aware to support |
| 12 | non-ASCII passwords. Update documentation if this is done. | 31 | non-ASCII passwords. Update documentation if this is done. |
libqpdf/QPDF.cc
| @@ -1253,6 +1253,21 @@ QPDF::readObjectAtOffset(bool try_recovery, | @@ -1253,6 +1253,21 @@ QPDF::readObjectAtOffset(bool try_recovery, | ||
| 1253 | int& objid, int& generation) | 1253 | int& objid, int& generation) |
| 1254 | { | 1254 | { |
| 1255 | setLastObjectDescription(description, exp_objid, exp_generation); | 1255 | setLastObjectDescription(description, exp_objid, exp_generation); |
| 1256 | + | ||
| 1257 | + // Special case: if offset is 0, just return null. Some PDF | ||
| 1258 | + // writers, in particuar "Mac OS X 10.7.5 Quartz PDFContext", may | ||
| 1259 | + // store deleted objects in the xref table as "0000000000 00000 | ||
| 1260 | + // n", which is not correct, but it won't hurt anything for to | ||
| 1261 | + // ignore these. | ||
| 1262 | + if (offset == 0) | ||
| 1263 | + { | ||
| 1264 | + QTC::TC("qpdf", "QPDF bogus 0 offset", 0); | ||
| 1265 | + warn(QPDFExc(qpdf_e_damaged_pdf, this->file->getName(), | ||
| 1266 | + this->last_object_description, 0, | ||
| 1267 | + "object has offset 0")); | ||
| 1268 | + return QPDFObjectHandle::newNull(); | ||
| 1269 | + } | ||
| 1270 | + | ||
| 1256 | this->file->seek(offset, SEEK_SET); | 1271 | this->file->seek(offset, SEEK_SET); |
| 1257 | 1272 | ||
| 1258 | QPDFTokenizer::Token tobjid = readToken(this->file); | 1273 | QPDFTokenizer::Token tobjid = readToken(this->file); |
qpdf/qpdf.testcov
| @@ -242,3 +242,4 @@ QPDF_Tokenizer EOF reading token 0 | @@ -242,3 +242,4 @@ QPDF_Tokenizer EOF reading token 0 | ||
| 242 | QPDF_Tokenizer EOF reading appendable token 0 | 242 | QPDF_Tokenizer EOF reading appendable token 0 |
| 243 | QPDFWriter extra header text no newline 0 | 243 | QPDFWriter extra header text no newline 0 |
| 244 | QPDFWriter extra header text add newline 0 | 244 | QPDFWriter extra header text add newline 0 |
| 245 | +QPDF bogus 0 offset 0 |
qpdf/qtest/qpdf.test
| @@ -149,7 +149,7 @@ $td->runtest("remove page we don't have", | @@ -149,7 +149,7 @@ $td->runtest("remove page we don't have", | ||
| 149 | $td->NORMALIZE_NEWLINES); | 149 | $td->NORMALIZE_NEWLINES); |
| 150 | # ---------- | 150 | # ---------- |
| 151 | $td->notify("--- Miscellaneous Tests ---"); | 151 | $td->notify("--- Miscellaneous Tests ---"); |
| 152 | -$n_tests += 55; | 152 | +$n_tests += 56; |
| 153 | 153 | ||
| 154 | $td->runtest("qpdf version", | 154 | $td->runtest("qpdf version", |
| 155 | {$td->COMMAND => "qpdf --version"}, | 155 | {$td->COMMAND => "qpdf --version"}, |
| @@ -410,6 +410,10 @@ $td->runtest("output to custom pipeline", | @@ -410,6 +410,10 @@ $td->runtest("output to custom pipeline", | ||
| 410 | $td->runtest("check output", | 410 | $td->runtest("check output", |
| 411 | {$td->FILE => "a.pdf"}, | 411 | {$td->FILE => "a.pdf"}, |
| 412 | {$td->FILE => "custom-pipeline.pdf"}); | 412 | {$td->FILE => "custom-pipeline.pdf"}); |
| 413 | +$td->runtest("object with zero offset", | ||
| 414 | + {$td->COMMAND => "qpdf --check zero-offset.pdf"}, | ||
| 415 | + {$td->FILE => "zero-offset.out", $td->EXIT_STATUS => 3}, | ||
| 416 | + $td->NORMALIZE_NEWLINES); | ||
| 413 | 417 | ||
| 414 | show_ntests(); | 418 | show_ntests(); |
| 415 | # ---------- | 419 | # ---------- |
qpdf/qtest/qpdf/zero-offset.out
0 → 100644
qpdf/qtest/qpdf/zero-offset.pdf
0 → 100644
No preview for this file type