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

ROB: Cope with xref not followed by separator #2083

Merged
merged 2 commits into from
Aug 12, 2023
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
4 changes: 2 additions & 2 deletions pypdf/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1634,8 +1634,8 @@ def _find_startxref_pos(self, stream: StreamType) -> int:

def _read_standard_xref_table(self, stream: StreamType) -> None:
# standard cross-reference table
ref = stream.read(4)
if ref[:3] != b"ref":
ref = stream.read(3)
if ref != b"ref":
raise PdfReadError("xref table read error")
read_non_whitespace(stream)
stream.seek(-1, 1)
Expand Down
14 changes: 14 additions & 0 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1436,3 +1436,17 @@ def test_iss1825():
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
page = reader.pages[0]
page.extract_text()


@pytest.mark.enable_socket()
def test_iss2082():
url = "https://github.com/py-pdf/pypdf/files/12317939/test.pdf"
name = "iss2082.pdf"
b = get_data_from_url(url, name=name)
reader = PdfReader(BytesIO(b))
reader.pages[0].extract_text()

bb = bytearray(b)
bb[b.find(b"xref") + 2] = ord(b"E")
with pytest.raises(PdfReadError):
reader = PdfReader(BytesIO(bb))