Commit 551dfbf697736b8cae677d87b7931b5f23f830b8
1 parent
ed62be88
Allow set*EncryptionParameters before filename iset (fixes #336)
Showing
6 changed files
with
59 additions
and
1 deletions
ChangeLog
libqpdf/QPDFWriter.cc
manual/qpdf-manual.xml
| ... | ... | @@ -4344,6 +4344,15 @@ print "\n"; |
| 4344 | 4344 | when qpdf is invoked as an AppImage. |
| 4345 | 4345 | </para> |
| 4346 | 4346 | </listitem> |
| 4347 | + <listitem> | |
| 4348 | + <para> | |
| 4349 | + Calling | |
| 4350 | + <function>QPDFWriter::set*EncryptionParameters</function> on | |
| 4351 | + a <classname>QPDFWriter</classname> object whose output | |
| 4352 | + filename has not yet been set no longer produces a | |
| 4353 | + segmentation fault. | |
| 4354 | + </para> | |
| 4355 | + </listitem> | |
| 4347 | 4356 | </itemizedlist> |
| 4348 | 4357 | </listitem> |
| 4349 | 4358 | <listitem> | ... | ... |
qpdf/qtest/qpdf.test
| ... | ... | @@ -3522,6 +3522,19 @@ foreach my $d (@enc_key) |
| 3522 | 3522 | $td->NORMALIZE_NEWLINES); |
| 3523 | 3523 | } |
| 3524 | 3524 | |
| 3525 | +# Miscellaneous encryption tests | |
| 3526 | +$n_tests += 2; | |
| 3527 | + | |
| 3528 | +$td->runtest("set encryption before set filename", | |
| 3529 | + {$td->COMMAND => "test_driver 63 minimal.pdf"}, | |
| 3530 | + {$td->STRING => "test 63 done\n", $td->EXIT_STATUS => 0}, | |
| 3531 | + $td->NORMALIZE_NEWLINES); | |
| 3532 | +$td->runtest("check file's validity", | |
| 3533 | + {$td->COMMAND => "qpdf --check --password=u a.pdf"}, | |
| 3534 | + {$td->FILE => "encrypt-before-filename.out", | |
| 3535 | + $td->EXIT_STATUS => 0}, | |
| 3536 | + $td->NORMALIZE_NEWLINES); | |
| 3537 | + | |
| 3525 | 3538 | show_ntests(); |
| 3526 | 3539 | # ---------- |
| 3527 | 3540 | $td->notify("--- Unicode Passwords ---"); | ... | ... |
qpdf/qtest/qpdf/encrypt-before-filename.out
0 → 100644
| 1 | +checking a.pdf | |
| 2 | +PDF Version: 1.7 extension level 8 | |
| 3 | +R = 6 | |
| 4 | +P = -4 | |
| 5 | +User password = u | |
| 6 | +extract for accessibility: allowed | |
| 7 | +extract for any purpose: allowed | |
| 8 | +print low resolution: allowed | |
| 9 | +print high resolution: allowed | |
| 10 | +modify document assembly: allowed | |
| 11 | +modify forms: allowed | |
| 12 | +modify annotations: allowed | |
| 13 | +modify other: allowed | |
| 14 | +modify anything: allowed | |
| 15 | +stream encryption method: AESv3 | |
| 16 | +string encryption method: AESv3 | |
| 17 | +file encryption method: AESv3 | |
| 18 | +File is not linearized | |
| 19 | +No syntax or stream encoding errors found; the file may still contain | |
| 20 | +errors that qpdf cannot detect | ... | ... |
qpdf/test_driver.cc
| ... | ... | @@ -2094,6 +2094,19 @@ void runtest(int n, char const* filename1, char const* arg2) |
| 2094 | 2094 | assert_compare_numbers(INT_MAX, t.getKey("/Q3").getIntValueAsInt()); |
| 2095 | 2095 | assert_compare_numbers(UINT_MAX, t.getKey("/Q3").getUIntValueAsUInt()); |
| 2096 | 2096 | } |
| 2097 | + else if (n == 63) | |
| 2098 | + { | |
| 2099 | + QPDFWriter w(pdf); | |
| 2100 | + // Exercise setting encryption parameters before setting the | |
| 2101 | + // output filename. The previous bug does not happen if static | |
| 2102 | + // or deterministic ID is used because the filename is not | |
| 2103 | + // used as part of the input data for ID generation in those | |
| 2104 | + // cases. | |
| 2105 | + w.setR6EncryptionParameters( | |
| 2106 | + "u", "o", true, true, true, true, true, true, qpdf_r3p_full, true); | |
| 2107 | + w.setOutputFilename("a.pdf"); | |
| 2108 | + w.write(); | |
| 2109 | + } | |
| 2097 | 2110 | else |
| 2098 | 2111 | { |
| 2099 | 2112 | throw std::runtime_error(std::string("invalid test ") + | ... | ... |