preserve /EncryptMetadata when copying encryption parameters

This commit is contained in:
Jay Berkenbilt 2011-08-10 19:47:18 -04:00
parent 8b0fbfe806
commit a42a4068b5
4 changed files with 25 additions and 2 deletions

View File

@ -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

View File

@ -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(),

View File

@ -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

View File

@ -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";
}
}