aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDFWriter.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2018-02-05 00:02:56 +0100
committerJay Berkenbilt <ejb@ql.org>2018-02-05 00:16:23 +0100
commite3167c1a609a1f5262d8308dd94845d557e235d8 (patch)
tree1dfac8fd5c3419a9d17b4971e0ef55bc10cc8730 /libqpdf/QPDFWriter.cc
parent9732de7ea4689f5dc7e4139cf580c457a3cf41d9 (diff)
downloadqpdf-e3167c1a609a1f5262d8308dd94845d557e235d8.tar.zst
Fix linearization for files with nonstandard ID length
Diffstat (limited to 'libqpdf/QPDFWriter.cc')
-rw-r--r--libqpdf/QPDFWriter.cc47
1 files changed, 39 insertions, 8 deletions
diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc
index d34b095c..05446400 100644
--- a/libqpdf/QPDFWriter.cc
+++ b/libqpdf/QPDFWriter.cc
@@ -1246,8 +1246,28 @@ QPDFWriter::writeTrailer(trailer_e which, int size, bool xref_stream,
writeString(" /ID [");
if (linearization_pass == 1)
{
- writeString("<00000000000000000000000000000000>"
- "<00000000000000000000000000000000>");
+ std::string original_id1 = getOriginalID1();
+ if (original_id1.empty())
+ {
+ writeString("<00000000000000000000000000000000>");
+ }
+ else
+ {
+ // Write a string of zeroes equal in length to the
+ // representation of the original ID. While writing the
+ // original ID would have the same number of bytes, it
+ // would cause a change to the deterministic ID generated
+ // by older versions of the software that hard-coded the
+ // length of the ID to 16 bytes.
+ writeString("<");
+ size_t len = QPDF_String(original_id1).unparse(true).length() - 2;
+ for (size_t i = 0; i < len; ++i)
+ {
+ writeString("0");
+ }
+ writeString(">");
+ }
+ writeString("<00000000000000000000000000000000>");
}
else
{
@@ -1952,6 +1972,20 @@ QPDFWriter::writeObject(QPDFObjectHandle object, int object_stream_index)
}
}
+std::string
+QPDFWriter::getOriginalID1()
+{
+ QPDFObjectHandle trailer = this->m->pdf.getTrailer();
+ if (trailer.hasKey("/ID"))
+ {
+ return trailer.getKey("/ID").getArrayItem(0).getStringValue();
+ }
+ else
+ {
+ return "";
+ }
+}
+
void
QPDFWriter::generateID()
{
@@ -2042,12 +2076,9 @@ QPDFWriter::generateID()
// generated ID for both.
this->m->id2 = result;
- if (trailer.hasKey("/ID"))
- {
- // Note: keep /ID from old file even if --static-id was given.
- this->m->id1 = trailer.getKey("/ID").getArrayItem(0).getStringValue();
- }
- else
+ // Note: keep /ID from old file even if --static-id was given.
+ this->m->id1 = getOriginalID1();
+ if (this->m->id1.empty())
{
this->m->id1 = this->m->id2;
}