aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-06-23 02:05:18 +0200
committerJay Berkenbilt <ejb@ql.org>2019-06-23 02:57:33 +0200
commit551dfbf697736b8cae677d87b7931b5f23f830b8 (patch)
tree04955d347d758e871fce229029085a518ec59f88
parented62be888cdab0c84d4dd2799f8e4727cfaaf9d6 (diff)
downloadqpdf-551dfbf697736b8cae677d87b7931b5f23f830b8.tar.zst
Allow set*EncryptionParameters before filename iset (fixes #336)
-rw-r--r--ChangeLog3
-rw-r--r--libqpdf/QPDFWriter.cc2
-rw-r--r--manual/qpdf-manual.xml9
-rw-r--r--qpdf/qtest/qpdf.test13
-rw-r--r--qpdf/qtest/qpdf/encrypt-before-filename.out20
-rw-r--r--qpdf/test_driver.cc13
6 files changed, 59 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index a7f9ba35..efb1d789 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc
index 41d5ab30..2df18452 100644
--- a/libqpdf/QPDFWriter.cc
+++ b/libqpdf/QPDFWriter.cc
@@ -26,7 +26,7 @@
QPDFWriter::Members::Members(QPDF& pdf) :
pdf(pdf),
- filename(0),
+ filename("unspecified"),
file(0),
close_file(false),
buffer_pipeline(0),
diff --git a/manual/qpdf-manual.xml b/manual/qpdf-manual.xml
index b64b2b3b..3bd1f259 100644
--- a/manual/qpdf-manual.xml
+++ b/manual/qpdf-manual.xml
@@ -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>
diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test
index e1db8b89..0274f604 100644
--- a/qpdf/qtest/qpdf.test
+++ b/qpdf/qtest/qpdf.test
@@ -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 ---");
diff --git a/qpdf/qtest/qpdf/encrypt-before-filename.out b/qpdf/qtest/qpdf/encrypt-before-filename.out
new file mode 100644
index 00000000..e7d7dbd4
--- /dev/null
+++ b/qpdf/qtest/qpdf/encrypt-before-filename.out
@@ -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
diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc
index 7fb84a8f..7aed39ba 100644
--- a/qpdf/test_driver.cc
+++ b/qpdf/test_driver.cc
@@ -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 ") +