Allow set*EncryptionParameters before filename iset (fixes #336)

This commit is contained in:
Jay Berkenbilt 2019-06-22 20:05:18 -04:00
parent ed62be888c
commit 551dfbf697
6 changed files with 59 additions and 1 deletions

View File

@ -1,5 +1,8 @@
2019-06-22 Jay Berkenbilt <ejb@ql.org>
* QPDFWriter: allow calling set*EncryptionParameters before
calling setFilename. Fixes #336.
* It now works to run --completion-bash and --completion-zsh when
qpdf is started from an AppImage.

View File

@ -26,7 +26,7 @@
QPDFWriter::Members::Members(QPDF& pdf) :
pdf(pdf),
filename(0),
filename("unspecified"),
file(0),
close_file(false),
buffer_pipeline(0),

View File

@ -4344,6 +4344,15 @@ print "\n";
when qpdf is invoked as an AppImage.
</para>
</listitem>
<listitem>
<para>
Calling
<function>QPDFWriter::set*EncryptionParameters</function> on
a <classname>QPDFWriter</classname> object whose output
filename has not yet been set no longer produces a
segmentation fault.
</para>
</listitem>
</itemizedlist>
</listitem>
<listitem>

View File

@ -3522,6 +3522,19 @@ foreach my $d (@enc_key)
$td->NORMALIZE_NEWLINES);
}
# Miscellaneous encryption tests
$n_tests += 2;
$td->runtest("set encryption before set filename",
{$td->COMMAND => "test_driver 63 minimal.pdf"},
{$td->STRING => "test 63 done\n", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("check file's validity",
{$td->COMMAND => "qpdf --check --password=u a.pdf"},
{$td->FILE => "encrypt-before-filename.out",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
show_ntests();
# ----------
$td->notify("--- Unicode Passwords ---");

View File

@ -0,0 +1,20 @@
checking a.pdf
PDF Version: 1.7 extension level 8
R = 6
P = -4
User password = u
extract for accessibility: allowed
extract for any purpose: allowed
print low resolution: allowed
print high resolution: allowed
modify document assembly: allowed
modify forms: allowed
modify annotations: allowed
modify other: allowed
modify anything: allowed
stream encryption method: AESv3
string encryption method: AESv3
file encryption method: AESv3
File is not linearized
No syntax or stream encoding errors found; the file may still contain
errors that qpdf cannot detect

View File

@ -2094,6 +2094,19 @@ void runtest(int n, char const* filename1, char const* arg2)
assert_compare_numbers(INT_MAX, t.getKey("/Q3").getIntValueAsInt());
assert_compare_numbers(UINT_MAX, t.getKey("/Q3").getUIntValueAsUInt());
}
else if (n == 63)
{
QPDFWriter w(pdf);
// Exercise setting encryption parameters before setting the
// output filename. The previous bug does not happen if static
// or deterministic ID is used because the filename is not
// used as part of the input data for ID generation in those
// cases.
w.setR6EncryptionParameters(
"u", "o", true, true, true, true, true, true, qpdf_r3p_full, true);
w.setOutputFilename("a.pdf");
w.write();
}
else
{
throw std::runtime_error(std::string("invalid test ") +