From 727406cbacd23c97f489344e1f9a82c742f97ecc Mon Sep 17 00:00:00 2001 From: Kushal Kumaran Date: Mon, 27 Dec 2010 16:03:35 +0530 Subject: [PATCH] Only compare first 16 bytes of U entry when decrypting revision 3 or greater. --- pyPdf/pdf.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyPdf/pdf.py b/pyPdf/pdf.py index bf60d01..57e738b 100644 --- a/pyPdf/pdf.py +++ b/pyPdf/pdf.py @@ -936,15 +936,16 @@ def _authenticateUserPassword(self, password): p_entry = encrypt['/P'].getObject() id_entry = self.trailer['/ID'].getObject() id1_entry = id_entry[0].getObject() + real_U = encrypt['/U'].getObject().original_bytes if rev == 2: U, key = _alg34(password, owner_entry, p_entry, id1_entry) + return U == real_U, key elif rev >= 3: U, key = _alg35(password, rev, encrypt["/Length"].getObject() / 8, owner_entry, p_entry, id1_entry, encrypt.get("/EncryptMetadata", BooleanObject(False)).getObject()) - real_U = encrypt['/U'].getObject().original_bytes - return U == real_U, key + return U[:16] == real_U[:16], key def getIsEncrypted(self): return self.trailer.has_key("/Encrypt")