summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2011-08-11 01:47:18 +0200
committerJay Berkenbilt <ejb@ql.org>2011-08-11 01:47:18 +0200
commita42a4068b5ebdf557d2815ee1c72a27ebfefd3f5 (patch)
treee980929509e8b545194bc0b8348ff206d98096bd
parent8b0fbfe8065140db3c4319b715bdeb69558828c6 (diff)
downloadqpdf-a42a4068b5ebdf557d2815ee1c72a27ebfefd3f5.tar.zst
preserve /EncryptMetadata when copying encryption parameters
-rw-r--r--ChangeLog5
-rw-r--r--libqpdf/QPDFWriter.cc8
-rw-r--r--qpdf/qpdf.testcov1
-rw-r--r--qpdf/qtest/qpdf.test13
4 files changed, 25 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 5fdb0464..454cf44c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2011-08-10 Jay Berkenbilt <ejb@ql.org>
+ * libqpdf/QPDFWriter.cc (copyEncryptionParameters): preserve
+ whether metadata is encryption. This fixes part of bug 3173659:
+ the password becomes invalid if qpdf copies an encrypted file with
+ cleartext-metadata.
+
* include/qpdf/QPDFWriter.hh: add a new constructor that takes
only a QPDF reference and leaves specification of output for
later. Add methods setOutputFilename() to set the output to a
diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc
index 7217ded7..99433a16 100644
--- a/libqpdf/QPDFWriter.cc
+++ b/libqpdf/QPDFWriter.cc
@@ -383,6 +383,14 @@ QPDFWriter::copyEncryptionParameters()
{
key_len = encrypt.getKey("/Length").getIntValue() / 8;
}
+ if (encrypt.hasKey("/EncryptMetadata") &&
+ encrypt.getKey("/EncryptMetadata").isBool())
+ {
+ this->encrypt_metadata =
+ encrypt.getKey("/EncryptMetadata").getBoolValue();
+ }
+ QTC::TC("qpdf", "QPDFWriter copy encrypt metadata",
+ this->encrypt_metadata ? 0 : 1);
setEncryptionParametersInternal(
V,
encrypt.getKey("/R").getIntValue(),
diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov
index 37ad350a..8f5d15a3 100644
--- a/qpdf/qpdf.testcov
+++ b/qpdf/qpdf.testcov
@@ -193,3 +193,4 @@ QPDF stream with CR only 0
QPDF stream with CRNL 0
QPDF stream with NL only 0
QPDF replaceObject called with indirect object 0
+QPDFWriter copy encrypt metadata 1
diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test
index de82ce3b..c428aec3 100644
--- a/qpdf/qtest/qpdf.test
+++ b/qpdf/qtest/qpdf.test
@@ -755,7 +755,7 @@ $td->runtest("show-xref-by-id-filtered",
show_ntests();
# ----------
$td->notify("--- Clear-text Metadata Tests ---");
-$n_tests += 42;
+$n_tests += 58;
# args: file, exp_encrypted, exp_cleartext
check_metadata("compressed-metadata.pdf", 0, 0);
@@ -787,13 +787,22 @@ foreach my $f (qw(compressed-metadata.pdf enc-base.pdf))
" a.pdf b.pdf"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
check_metadata("b.pdf", 1, 1);
- unlink "b.pdf";
+ $td->runtest("preserve encryption",
+ {$td->COMMAND => "qpdf b.pdf c.pdf"},
+ {$td->STRING => "", $td->EXIT_STATUS => 0});
+ check_metadata("c.pdf", 1, 1);
+ unlink "b.pdf", "c.pdf";
$td->runtest("encrypt with aes and cleartext metadata",
{$td->COMMAND =>
"qpdf --encrypt '' '' 128" .
" --cleartext-metadata --use-aes=y -- a.pdf b.pdf"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
check_metadata("b.pdf", 1, 1);
+ $td->runtest("preserve encryption",
+ {$td->COMMAND => "qpdf b.pdf c.pdf"},
+ {$td->STRING => "", $td->EXIT_STATUS => 0});
+ check_metadata("c.pdf", 1, 1);
+ unlink "b.pdf", "c.pdf";
}
}