From 5e0ba126871c57a8a688b36614f2b8d78c2675b3 Mon Sep 17 00:00:00 2001 From: Masamichi Hosoda Date: Thu, 26 Sep 2019 23:36:14 +0900 Subject: Fix /Contents value representation in a signature dictionary Table 8.93 "Entries in a signature dictionary" in PDF 1.5 reference describes that the value of Contents entry is a hexadecimal string representation when ByteRange is specified. This commit makes QPDF always uses hexadecimal strings representation instead of literal strings for it. --- libqpdf/QPDFWriter.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'libqpdf/QPDFWriter.cc') diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index 116d493f..4397c3ad 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -1687,7 +1687,20 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, writeStringNoQDF(" "); writeString(QPDF_Name::normalizeName(key)); writeString(" "); - unparseChild(object.getKey(key), level + 1, child_flags); + if (key == "/Contents" && + object.hasKey("/Type") && + object.getKey("/Type").isName() && + object.getKey("/Type").getName() == "/Sig" && + object.hasKey("/ByteRange")) + { + QTC::TC("qpdf", "QPDFWriter no encryption sig contents"); + unparseChild(object.getKey(key), level + 1, + child_flags | f_hex_string); + } + else + { + unparseChild(object.getKey(key), level + 1, child_flags); + } writeStringQDF("\n"); } @@ -1882,6 +1895,10 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, val = QPDF_String(std::string(tmp, vlen)).unparse(); } } + else if (flags & f_hex_string) + { + val = QPDF_String(object.getStringValue()).unparse(true); + } else { val = object.unparseResolved(); -- cgit v1.2.3-54-g00ecf