mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-02 22:50:20 +00:00
Allow set*EncryptionParameters before filename iset (fixes #336)
This commit is contained in:
parent
ed62be888c
commit
551dfbf697
@ -1,5 +1,8 @@
|
|||||||
2019-06-22 Jay Berkenbilt <ejb@ql.org>
|
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
|
* It now works to run --completion-bash and --completion-zsh when
|
||||||
qpdf is started from an AppImage.
|
qpdf is started from an AppImage.
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
QPDFWriter::Members::Members(QPDF& pdf) :
|
QPDFWriter::Members::Members(QPDF& pdf) :
|
||||||
pdf(pdf),
|
pdf(pdf),
|
||||||
filename(0),
|
filename("unspecified"),
|
||||||
file(0),
|
file(0),
|
||||||
close_file(false),
|
close_file(false),
|
||||||
buffer_pipeline(0),
|
buffer_pipeline(0),
|
||||||
|
@ -4344,6 +4344,15 @@ print "\n";
|
|||||||
when qpdf is invoked as an AppImage.
|
when qpdf is invoked as an AppImage.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</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>
|
</itemizedlist>
|
||||||
</listitem>
|
</listitem>
|
||||||
<listitem>
|
<listitem>
|
||||||
|
@ -3522,6 +3522,19 @@ foreach my $d (@enc_key)
|
|||||||
$td->NORMALIZE_NEWLINES);
|
$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();
|
show_ntests();
|
||||||
# ----------
|
# ----------
|
||||||
$td->notify("--- Unicode Passwords ---");
|
$td->notify("--- Unicode Passwords ---");
|
||||||
|
20
qpdf/qtest/qpdf/encrypt-before-filename.out
Normal file
20
qpdf/qtest/qpdf/encrypt-before-filename.out
Normal 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
|
@ -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(INT_MAX, t.getKey("/Q3").getIntValueAsInt());
|
||||||
assert_compare_numbers(UINT_MAX, t.getKey("/Q3").getUIntValueAsUInt());
|
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
|
else
|
||||||
{
|
{
|
||||||
throw std::runtime_error(std::string("invalid test ") +
|
throw std::runtime_error(std::string("invalid test ") +
|
||||||
|
Loading…
Reference in New Issue
Block a user