Skip to content

Commit

Permalink
BUG: Cope with unbalanced delimiters in dictionary object (#2878)
Browse files Browse the repository at this point in the history
Closes #2877.
  • Loading branch information
pubpub-zz authored Sep 27, 2024
1 parent 425dbf3 commit 2e69836
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
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_dictionary_object(caplog):
"""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

0 comments on commit 2e69836

Please sign in to comment.