From 06b818dcd39b5aeaeeee5c247483633a02a0222e Mon Sep 17 00:00:00 2001 From: Masamichi Hosoda Date: Fri, 27 Sep 2019 21:00:30 +0900 Subject: Exclude signature dictionary from compressible objects It seems better not to compress signature dictionaries. Various PDF digital signing tools, including Adobe Acrobat Reader DC, do not compress signature dictionaries. Table 8.93 "Entries in a signature dictionary" in PDF 1.5 reference describes that /ByteRange in the signature dictionary shall be used to describe a digest that does not include the signature value (/Contents) itself. The byte ranges cannot be determined if the dictionary is compressed. --- libqpdf/QPDF.cc | 8 +++++++- qpdf/qtest/qpdf.test | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index c546fbe1..6c0c700a 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -2673,7 +2673,13 @@ QPDF::getCompressibleObjGens() { QTC::TC("qpdf", "QPDF exclude encryption dictionary"); } - else if (! obj.isStream()) + else if ((! obj.isStream()) && + (! (obj.isDictionary() && + obj.hasKey("/ByteRange") && + obj.hasKey("/Contents") && + obj.hasKey("/Type") && + obj.getKey("/Type").isName() && + obj.getKey("/Type").getName() == "/Sig"))) { result.push_back(og); } diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index 9fdf9ba2..d5caa9ad 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -3998,9 +3998,9 @@ $td->runtest("fix-qdf with big object stream", # > 255 objects in a stream show_ntests(); # ---------- $td->notify("--- Signature Dictionary ---"); -$n_tests += 4; +$n_tests += 6; -foreach my $i (qw(preserve disable)) +foreach my $i (qw(preserve disable generate)) { $td->runtest("sig dict contents hex (object-streams=$i)", {$td->COMMAND => -- cgit v1.2.3-54-g00ecf