Skip to content

Commit

Permalink
Resolve IndirectObject when it refers to a free entry.
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Karvonen committed Jul 4, 2022
1 parent 04d576c commit daea3e1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions PyPDF2/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,9 @@ def _get_outlines(
# so continue to load the file without the Bookmarks
return outlines

if isinstance(lines, NullObject):
return outlines

# TABLE 8.3 Entries in the outline dictionary
if "/First" in lines:
node = cast(DictionaryObject, lines["/First"])
Expand Down Expand Up @@ -1052,6 +1055,10 @@ def get_object(self, indirect_reference: IndirectObject) -> Optional[PdfObject]:
indirect_reference.generation in self.xref
and indirect_reference.idnum in self.xref[indirect_reference.generation]
):
if self.xref_free_entry.get(indirect_reference.generation, {}).get(
indirect_reference.idnum, False
):
return NullObject()
start = self.xref[indirect_reference.generation][indirect_reference.idnum]
self.stream.seek(start, 0)
idnum, generation = self.read_object_header(self.stream)
Expand Down Expand Up @@ -1225,6 +1232,7 @@ def read(self, stream: StreamType) -> None:

# read all cross reference tables and their trailers
self.xref: Dict[int, Dict[Any, Any]] = {}
self.xref_free_entry: Dict[int, Dict[Any, Any]] = {}
self.xref_objStm: Dict[int, Tuple[Any, Any]] = {}
self.trailer = DictionaryObject()
while True:
Expand Down Expand Up @@ -1380,9 +1388,12 @@ def _read_standard_xref_table(self, stream: StreamType) -> None:
stream.seek(-1, 1)

offset_b, generation_b = line[:16].split(b" ")
entry_type_b = line[17:18]

offset, generation = int(offset_b), int(generation_b)
if generation not in self.xref:
self.xref[generation] = {}
self.xref_free_entry[generation] = {}
if num in self.xref[generation]:
# It really seems like we should allow the last
# xref table in the file to override previous
Expand All @@ -1391,6 +1402,7 @@ def _read_standard_xref_table(self, stream: StreamType) -> None:
pass
else:
self.xref[generation][num] = offset
self.xref_free_entry[generation][num] = entry_type_b == b"f"
cnt += 1
num += 1
read_non_whitespace(stream)
Expand Down

0 comments on commit daea3e1

Please sign in to comment.