Skip to content

Commit

Permalink
ROB: Invalid startxref pointing 1 char before (#1784)
Browse files Browse the repository at this point in the history
Fixes #1756
  • Loading branch information
pubpub-zz committed Apr 14, 2023
1 parent 6836174 commit bc12516
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pypdf/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,8 @@ def _get_xref_issues(stream: StreamType, startxref: int) -> int:
"""
stream.seek(startxref - 1, 0) # -1 to check character before
line = stream.read(1)
if line == b"j":
line = stream.read(1)
if line not in b"\r\n \t":
return 1
line = stream.read(4)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1392,3 +1392,12 @@ def test_broken_file_header():
pdf_data.find(b"xref") - 1,
)
PdfReader(io.BytesIO(pdf_data))


@pytest.mark.enable_socket()
def test_iss1756():
url = "https://github.com/py-pdf/pypdf/files/11105591/641-Attachment-B-Pediatric-Cardiac-Arrest-8-1-2019.pdf"
name = "iss1756.pdf"
in_pdf = PdfReader(BytesIO(get_pdf_from_url(url, name=name)))
in_pdf.trailer["/ID"]
# removed to cope with missing cryptodome during commit check : len(in_pdf.pages)

0 comments on commit bc12516

Please sign in to comment.