Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: u_hash in AlgV4.compute_key #1170

Merged
merged 2 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions PyPDF2/_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def compute_key(
u_hash.update(o_entry)
u_hash.update(struct.pack("<I", P))
u_hash.update(id1_entry)
if rev >= 3 and not metadata_encrypted:
if rev >= 4 and metadata_encrypted is False:
u_hash.update(b"\xff\xff\xff\xff")
u_hash_digest = u_hash.digest()
length = key_size // 8
Expand Down Expand Up @@ -772,7 +772,9 @@ def verify_v4(self, password: bytes) -> Tuple[bytes, PasswordType]:
R = cast(int, self.entry["/R"])
P = cast(int, self.entry["/P"])
P = (P + 0x100000000) % 0x100000000 # maybe < 0
metadata_encrypted = self.entry.get("/EncryptMetadata", True)
# make type(metadata_encrypted) == bool
em = self.entry.get("/EncryptMetadata")
metadata_encrypted = em.value if em else True
o_entry = cast(ByteStringObject, self.entry["/O"].get_object()).original_bytes
u_entry = cast(ByteStringObject, self.entry["/U"].get_object()).original_bytes

Expand Down
1 change: 0 additions & 1 deletion tests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ def test_text_extraction_issue_1091():
page.extract_text()


@pytest.mark.xfail(reason="#1088")
def test_empyt_password_1088():
url = "https://corpora.tika.apache.org/base/docs/govdocs1/941/941536.pdf"
name = "tika-941536.pdf"
Expand Down