Skip to content

Commit 5e17fb2

Browse files
committed
fix if u_value contains redundant data
1 parent eb0be4d commit 5e17fb2

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

PyPDF2/_encryption.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,10 +516,10 @@ def verify_owner_password(
516516
should match the value in the P key.
517517
"""
518518
password = password[:127]
519-
if AlgV5.calculate_hash(R, password, o_value[32:40], u_value) != o_value[:32]:
519+
if AlgV5.calculate_hash(R, password, o_value[32:40], u_value[:48]) != o_value[:32]:
520520
return b""
521521
iv = bytes(0 for _ in range(16))
522-
tmp_key = AlgV5.calculate_hash(R, password, o_value[40:], u_value)
522+
tmp_key = AlgV5.calculate_hash(R, password, o_value[40:48], u_value[:48])
523523
key = AES_CBC_decrypt(tmp_key, iv, oe_value)
524524
return key
525525

@@ -532,7 +532,7 @@ def verify_user_password(
532532
if AlgV5.calculate_hash(R, password, u_value[32:40], b"") != u_value[:32]:
533533
return b""
534534
iv = bytes(0 for _ in range(16))
535-
tmp_key = AlgV5.calculate_hash(R, password, u_value[40:], b"")
535+
tmp_key = AlgV5.calculate_hash(R, password, u_value[40:48], b"")
536536
return AES_CBC_decrypt(tmp_key, iv, ue_value)
537537

538538
@staticmethod

0 commit comments

Comments
 (0)