Skip to content

Commit 2e69836

Browse files
authored
BUG: Cope with unbalanced delimiters in dictionary object (#2878)
Closes #2877.
1 parent 425dbf3 commit 2e69836

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

pypdf/generic/_data_structures.py

+2
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,8 @@ def read_unsized_from_stream(
570570
try:
571571
try:
572572
key = read_object(stream, pdf)
573+
if isinstance(key, NullObject):
574+
break
573575
if not isinstance(key, NameObject):
574576
raise PdfReadError(
575577
f"Expecting a NameObject for key but found {key!r}"

tests/test_reader.py

+9
Original file line numberDiff line numberDiff line change
@@ -1703,3 +1703,12 @@ def test_space_in_names_to_continue_processing(caplog):
17031703
reader = PdfReader(BytesIO(b), strict=True)
17041704
with pytest.raises(PdfReadError):
17051705
obj = reader.get_object(70)
1706+
1707+
1708+
@pytest.mark.enable_socket()
1709+
def test_unbalanced_brackets_in_dictionary_object(caplog):
1710+
"""Cf #2877"""
1711+
url = "https://github.com/user-attachments/files/17162634/7f40cb209fb97d1782bffcefc5e7be40.pdf"
1712+
name = "iss2877.pdf" # reused
1713+
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
1714+
assert len(reader.pages) == 43 # note: /Count = 46 but 3 kids are None

0 commit comments

Comments
 (0)