summaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDF_encryption.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-06-23 02:45:10 +0200
committerJay Berkenbilt <ejb@ql.org>2019-06-23 02:57:33 +0200
commitc5ed1b8075f412b2e9cfd9cf01f41ba04d3af2bc (patch)
tree0e6346b7109b3e133a7796cb3f7c8b4fb212798a /libqpdf/QPDF_encryption.cc
parent551dfbf697736b8cae677d87b7931b5f23f830b8 (diff)
downloadqpdf-c5ed1b8075f412b2e9cfd9cf01f41ba04d3af2bc.tar.zst
Handle invalid encryption Length (fixes #333)
Diffstat (limited to 'libqpdf/QPDF_encryption.cc')
-rw-r--r--libqpdf/QPDF_encryption.cc42
1 files changed, 29 insertions, 13 deletions
diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc
index b5f16e0c..b15cb29d 100644
--- a/libqpdf/QPDF_encryption.cc
+++ b/libqpdf/QPDF_encryption.cc
@@ -935,22 +935,38 @@ QPDF::initializeEncryption()
pad_short_parameter(Perms, Perms_key_bytes_V5);
}
- int Length = 40;
- if (encryption_dict.getKey("/Length").isInteger())
+ int Length = 0;
+ if (V <= 1)
{
- Length = encryption_dict.getKey("/Length").getIntValueAsInt();
- if (R < 3)
+ Length = 40;
+ }
+ else if (V == 4)
+ {
+ Length = 128;
+ }
+ else if (V == 5)
+ {
+ Length = 256;
+ }
+ else
+ {
+ if (encryption_dict.getKey("/Length").isInteger())
+ {
+ Length = encryption_dict.getKey("/Length").getIntValueAsInt();
+ if ((Length % 8) || (Length < 40) || (Length > 128))
+ {
+ Length = 0;
+ }
+ }
+ if (Length == 0)
{
- // Force Length to 40 regardless of what the file says.
- Length = 40;
+ Length = 128;
}
- if ((Length % 8) || (Length < 40) || (Length > 256))
- {
- throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
- "encryption dictionary",
- this->m->file->getLastOffset(),
- "invalid /Length value in encryption dictionary");
- }
+ }
+ if (Length == 0)
+ {
+ // Still no Length? Just take a guess.
+ Length = 128;
}
this->m->encp->encrypt_metadata = true;