aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2012-11-20 19:15:14 +0100
committerJay Berkenbilt <ejb@ql.org>2012-11-20 19:57:37 +0100
commitf256670eba636a9b8344987108110e7b1b4c0a46 (patch)
treeda0cc0248dfc71cf2de5c76a60f99b9918d5c2d1
parent041397fdabde66574824db7582a26ef1e3fbfc65 (diff)
downloadqpdf-f256670eba636a9b8344987108110e7b1b4c0a46.tar.zst
Ignore objects with offset 0
-rw-r--r--ChangeLog6
-rw-r--r--TODO31
-rw-r--r--libqpdf/QPDF.cc15
-rw-r--r--qpdf/qpdf.testcov1
-rw-r--r--qpdf/qtest/qpdf.test6
-rw-r--r--qpdf/qtest/qpdf/zero-offset.out5
-rw-r--r--qpdf/qtest/qpdf/zero-offset.pdfbin0 -> 80678 bytes
7 files changed, 57 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index f023b09b..a13d4134 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2012-11-20 Jay Berkenbilt <ejb@ql.org>
+
+ * Ignore (with warning) non-freed objects in the xref table whose
+ offset is 0. Some PDF producers (incorrectly) do this. See
+ https://bugs.linuxfoundation.org/show_bug.cgi?id=1081.
+
2012-09-23 Jay Berkenbilt <ejb@ql.org>
* Add public methods QPDF::processInputSource and
diff --git a/TODO b/TODO
index ff3ecc83..be7ce1a2 100644
--- a/TODO
+++ b/TODO
@@ -1,12 +1,31 @@
General
=======
- * See if I can support the encryption format used with /R 5 /V 5,
- even though a qpdf-announce subscriber with an adobe.com email
- address mentioned that this is deprecated. There is also a new
- encryption format coming in a future release, which may be better
- to support. As of the qpdf 3.0 release, the specification was not
- publicly available yet.
+ * See if I can support the encryption format used with /R 5 /V 5
+ (AESV3), even though a qpdf-announce subscriber with an adobe.com
+ email address mentioned that this is deprecated. There is also a
+ new encryption format coming in a future release (PDF 2.0), which
+ may be better to support. As of the qpdf 3.0 release, the
+ specification was not publicly available yet.
+
+ AESV3 encryption is supported with PDF 1.7 extension level 3 and is
+ being deprecated, but there are plenty of files out there. The
+ encryption format is decribed in adobe_supplement_iso32000.pdf.
+ Such a file must specify that it uses these extensions in its
+ document catalog:
+
+ <<
+ /Type /Catalog
+ /Extensions <<
+ /ADBE <<
+ /BaseVersion /1.7
+ /ExtensionLevel 3
+ >>
+ >>
+ >>
+
+ Possible sha256 implementations: http://sol-biotech.com/code/sha2/,
+ http://hashlib2plus.sourceforge.net/
* Consider the possibility of doing something locale-aware to support
non-ASCII passwords. Update documentation if this is done.
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc
index 678f773e..ccbfaf7c 100644
--- a/libqpdf/QPDF.cc
+++ b/libqpdf/QPDF.cc
@@ -1253,6 +1253,21 @@ QPDF::readObjectAtOffset(bool try_recovery,
int& objid, int& generation)
{
setLastObjectDescription(description, exp_objid, exp_generation);
+
+ // Special case: if offset is 0, just return null. Some PDF
+ // writers, in particuar "Mac OS X 10.7.5 Quartz PDFContext", may
+ // store deleted objects in the xref table as "0000000000 00000
+ // n", which is not correct, but it won't hurt anything for to
+ // ignore these.
+ if (offset == 0)
+ {
+ QTC::TC("qpdf", "QPDF bogus 0 offset", 0);
+ warn(QPDFExc(qpdf_e_damaged_pdf, this->file->getName(),
+ this->last_object_description, 0,
+ "object has offset 0"));
+ return QPDFObjectHandle::newNull();
+ }
+
this->file->seek(offset, SEEK_SET);
QPDFTokenizer::Token tobjid = readToken(this->file);
diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov
index f9663375..3458297a 100644
--- a/qpdf/qpdf.testcov
+++ b/qpdf/qpdf.testcov
@@ -242,3 +242,4 @@ QPDF_Tokenizer EOF reading token 0
QPDF_Tokenizer EOF reading appendable token 0
QPDFWriter extra header text no newline 0
QPDFWriter extra header text add newline 0
+QPDF bogus 0 offset 0
diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test
index e510eded..16af5832 100644
--- a/qpdf/qtest/qpdf.test
+++ b/qpdf/qtest/qpdf.test
@@ -149,7 +149,7 @@ $td->runtest("remove page we don't have",
$td->NORMALIZE_NEWLINES);
# ----------
$td->notify("--- Miscellaneous Tests ---");
-$n_tests += 55;
+$n_tests += 56;
$td->runtest("qpdf version",
{$td->COMMAND => "qpdf --version"},
@@ -410,6 +410,10 @@ $td->runtest("output to custom pipeline",
$td->runtest("check output",
{$td->FILE => "a.pdf"},
{$td->FILE => "custom-pipeline.pdf"});
+$td->runtest("object with zero offset",
+ {$td->COMMAND => "qpdf --check zero-offset.pdf"},
+ {$td->FILE => "zero-offset.out", $td->EXIT_STATUS => 3},
+ $td->NORMALIZE_NEWLINES);
show_ntests();
# ----------
diff --git a/qpdf/qtest/qpdf/zero-offset.out b/qpdf/qtest/qpdf/zero-offset.out
new file mode 100644
index 00000000..df991469
--- /dev/null
+++ b/qpdf/qtest/qpdf/zero-offset.out
@@ -0,0 +1,5 @@
+checking zero-offset.pdf
+PDF Version: 1.3
+File is not encrypted
+File is not linearized
+WARNING: zero-offset.pdf (object 27 0): object has offset 0
diff --git a/qpdf/qtest/qpdf/zero-offset.pdf b/qpdf/qtest/qpdf/zero-offset.pdf
new file mode 100644
index 00000000..72e9e264
--- /dev/null
+++ b/qpdf/qtest/qpdf/zero-offset.pdf
Binary files differ