Commit 06b818dcd39b5aeaeeee5c247483633a02a0222e

Authored by Masamichi Hosoda
Committed by Jay Berkenbilt
1 parent 5e0ba126

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
@@ -2673,7 +2673,13 @@ QPDF::getCompressibleObjGens() @@ -2673,7 +2673,13 @@ QPDF::getCompressibleObjGens()
2673 { 2673 {
2674 QTC::TC("qpdf", "QPDF exclude encryption dictionary"); 2674 QTC::TC("qpdf", "QPDF exclude encryption dictionary");
2675 } 2675 }
2676 - else if (! obj.isStream()) 2676 + else if ((! obj.isStream()) &&
  2677 + (! (obj.isDictionary() &&
  2678 + obj.hasKey("/ByteRange") &&
  2679 + obj.hasKey("/Contents") &&
  2680 + obj.hasKey("/Type") &&
  2681 + obj.getKey("/Type").isName() &&
  2682 + obj.getKey("/Type").getName() == "/Sig")))
2677 { 2683 {
2678 result.push_back(og); 2684 result.push_back(og);
2679 } 2685 }
qpdf/qtest/qpdf.test
@@ -3998,9 +3998,9 @@ $td->runtest("fix-qdf with big object stream", # > 255 objects in a stream @@ -3998,9 +3998,9 @@ $td->runtest("fix-qdf with big object stream", # > 255 objects in a stream
3998 show_ntests(); 3998 show_ntests();
3999 # ---------- 3999 # ----------
4000 $td->notify("--- Signature Dictionary ---"); 4000 $td->notify("--- Signature Dictionary ---");
4001 -$n_tests += 4; 4001 +$n_tests += 6;
4002 4002
4003 -foreach my $i (qw(preserve disable)) 4003 +foreach my $i (qw(preserve disable generate))
4004 { 4004 {
4005 $td->runtest("sig dict contents hex (object-streams=$i)", 4005 $td->runtest("sig dict contents hex (object-streams=$i)",
4006 {$td->COMMAND => 4006 {$td->COMMAND =>