Skip to content

Commit b7f3811

Browse files
authoredFeb 27, 2025··
ROB: Avoid index errors on empty lines in xref table (#3162)
Closes #2886.
1 parent f15ddca commit b7f3811

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
 

‎pypdf/_reader.py

+2
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,8 @@ def _read_standard_xref_table(self, stream: StreamType) -> None:
747747
cnt = 0
748748
while cnt < size:
749749
line = stream.read(20)
750+
if not line:
751+
raise PdfReadError("Unexpected empty line in Xref table.")
750752

751753
# It's very clear in section 3.4.3 of the PDF spec
752754
# that all cross-reference table lines are a fixed

‎tests/test_reader.py

+10
Original file line numberDiff line numberDiff line change
@@ -1796,3 +1796,13 @@ def test_issue3151(caplog):
17961796
name = "issue3151.pdf"
17971797
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
17981798
assert len(reader.pages) == 742
1799+
1800+
1801+
@pytest.mark.enable_socket
1802+
def test_issue2886(caplog):
1803+
"""Tests for #2886"""
1804+
url = "https://github.com/user-attachments/files/17187711/crash-e8a85d82de01cab5eb44e7993304d8b9d1544970.pdf"
1805+
name = "issue2886.pdf"
1806+
1807+
with pytest.raises(PdfReadError, match="Unexpected empty line in Xref table."):
1808+
_ = PdfReader(BytesIO(get_data_from_url(url, name=name)))

0 commit comments

Comments
 (0)
Please sign in to comment.