Skip to content

Commit

Permalink
Merge branch 'main' into simplify-create-string
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma authored Jul 5, 2022
2 parents 6084516 + 02c601c commit a832ef6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 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
2 changes: 1 addition & 1 deletion tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ def test_extract_text_hello_world():


def test_read_path():
path = Path(os.path.join(RESOURCE_ROOT, "crazyones.pdf"))
path = Path(RESOURCE_ROOT, "crazyones.pdf")
reader = PdfReader(path)
assert len(reader.pages) == 1

Expand Down
10 changes: 10 additions & 0 deletions tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,13 @@ def test_get_fields():

# Cleanup
os.remove("tmp.txt")


def test_scale_rectangle_indirect_object():
url = "https://corpora.tika.apache.org/base/docs/govdocs1/999/999944.pdf"
name = "tika-999944.pdf"
data = BytesIO(get_pdf_from_url(url, name=name))
reader = PdfReader(data)

for page in reader.pages:
page.scale(sx=2, sy=3)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ deps =
pytest
pytest-cov
pycryptodome
commands = pytest tests --cov --cov-report term-missing -vv
commands = pytest tests --cov --cov-report term-missing -vv {posargs}

0 comments on commit a832ef6

Please sign in to comment.