aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDF_encryption.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2017-08-12 01:53:56 +0200
committerJay Berkenbilt <ejb@ql.org>2017-08-12 01:53:56 +0200
commit8fe0b06cd879f503d0e5be63f706d3adda3b8203 (patch)
tree0c2d106e5d5f686761e78e06020a27c501aa754a /libqpdf/QPDF_encryption.cc
parent0c99cf874b920f469bd6f7d65879b75a9c0af3fc (diff)
downloadqpdf-8fe0b06cd879f503d0e5be63f706d3adda3b8203.tar.zst
Pad encryption parameters that are too short (fixes #96)
Diffstat (limited to 'libqpdf/QPDF_encryption.cc')
-rw-r--r--libqpdf/QPDF_encryption.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc
index 71c28d0e..6c0c97ef 100644
--- a/libqpdf/QPDF_encryption.cc
+++ b/libqpdf/QPDF_encryption.cc
@@ -340,6 +340,16 @@ hash_V5(std::string const& password,
return result;
}
+static
+void pad_short_parameter(std::string& param, unsigned int max_len)
+{
+ if (param.length() < max_len)
+ {
+ QTC::TC("qpdf", "QPDF_encryption pad short parameter");
+ param.append(max_len - param.length(), '\0');
+ }
+}
+
std::string
QPDF::compute_data_key(std::string const& encryption_key,
int objid, int generation, bool use_aes,
@@ -876,6 +886,8 @@ QPDF::initializeEncryption()
if (V < 5)
{
+ pad_short_parameter(O, key_bytes);
+ pad_short_parameter(U, key_bytes);
if (! ((O.length() == key_bytes) && (U.length() == key_bytes)))
{
throw QPDFExc(qpdf_e_damaged_pdf, this->file->getName(),
@@ -899,6 +911,11 @@ QPDF::initializeEncryption()
UE = encryption_dict.getKey("/UE").getStringValue();
Perms = encryption_dict.getKey("/Perms").getStringValue();
+ pad_short_parameter(O, OU_key_bytes_V5);
+ pad_short_parameter(U, OU_key_bytes_V5);
+ pad_short_parameter(OE, OUE_key_bytes_V5);
+ pad_short_parameter(UE, OUE_key_bytes_V5);
+ pad_short_parameter(Perms, Perms_key_bytes_V5);
if ((O.length() < OU_key_bytes_V5) ||
(U.length() < OU_key_bytes_V5) ||
(OE.length() < OUE_key_bytes_V5) ||