File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -398,7 +398,8 @@ def get_object(
398398 self .stream .seek (m .start (0 ) + 1 )
399399 idnum , generation = self .read_object_header (self .stream )
400400 else :
401- idnum = - 1 # exception will be raised below
401+ idnum = - 1
402+ generation = - 1 # exception will be raised below
402403 if idnum != indirect_reference .idnum and self .xref_index :
403404 # Xref table probably had bad indexes due to not being zero-indexed
404405 if self .strict :
Original file line number Diff line number Diff line change @@ -1516,3 +1516,17 @@ def test_truncated_xref(caplog):
15161516 name = "iss2575.pdf"
15171517 PdfReader (BytesIO (get_data_from_url (url , name = name )))
15181518 assert "Invalid/Truncated xref table. Rebuilding it." in caplog .text
1519+
1520+
1521+ @pytest .mark .enable_socket ()
1522+ def test_damaged_pdf ():
1523+ url = "https://github.com/py-pdf/pypdf/files/15186107/malformed_pdf.pdf"
1524+ name = "malformed_pdf.pdf"
1525+ reader = PdfReader (BytesIO (get_data_from_url (url , name = name )), strict = False )
1526+ len (reader .pages )
1527+ strict_reader = PdfReader (BytesIO (get_data_from_url (url , name = name )), strict = True )
1528+ with pytest .raises (PdfReadError ) as exc :
1529+ len (strict_reader .pages )
1530+ assert (
1531+ exc .value .args [0 ] == "Expected object ID (21 0) does not match actual (-1 -1)."
1532+ )
You can’t perform that action at this time.
0 commit comments