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 ee30daa
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion PyPDF2/_reader.py
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 @@ -1379,10 +1387,11 @@ def _read_standard_xref_table(self, stream: StreamType) -> None:
if line[-1] in b"0123456789t":
stream.seek(-1, 1)

offset_b, generation_b = line[:16].split(b" ")
offset_b, generation_b, entry_type_b = line[:18].split(b" ")
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 +1400,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 ee30daa

Please sign in to comment.