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: Cope with unbalanced delimiters in dictionary object #2878

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions pypdf/generic/_data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,8 @@ def read_unsized_from_stream(
try:
try:
key = read_object(stream, pdf)
if isinstance(key, NullObject):
break
if not isinstance(key, NameObject):
raise PdfReadError(
f"Expecting a NameObject for key but found {key!r}"
Expand Down
9 changes: 9 additions & 0 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1703,3 +1703,12 @@ def test_space_in_names_to_continue_processing(caplog):
reader = PdfReader(BytesIO(b), strict=True)
with pytest.raises(PdfReadError):
obj = reader.get_object(70)


@pytest.mark.enable_socket()
def test_unbalanced_brackets_in_dictionnaryobject(caplog):
stefan6419846 marked this conversation as resolved.
Show resolved Hide resolved
"""Cf #2877"""
url = "https://github.com/user-attachments/files/17162634/7f40cb209fb97d1782bffcefc5e7be40.pdf"
name = "iss2877.pdf" # reused
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
assert len(reader.pages) == 43 # note: /Count = 46 but 3 kids are None
Loading