Skip to content

Commit

Permalink
ROB : Cope with null params for FitH /FitV destination (py-pdf#1145)
Browse files Browse the repository at this point in the history
iaw pdf spec, page 583
  • Loading branch information
pubpub-zz committed Jul 23, 2022
1 parent a6d27d7 commit 7d825ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
13 changes: 11 additions & 2 deletions PyPDF2/generic.py
Expand Up @@ -135,6 +135,9 @@ def writeToStream(
deprecate_with_replacement("writeToStream", "write_to_stream")
self.write_to_stream(stream, encryption_key)

def __repr__(self) -> str:
return "NullObject"

@staticmethod
def readFromStream(stream: StreamType) -> "NullObject": # pragma: no cover
deprecate_with_replacement("readFromStream", "read_from_stream")
Expand Down Expand Up @@ -1813,9 +1816,15 @@ def __init__(
self[NameObject(TA.TOP)],
) = args
elif typ in [TF.FIT_H, TF.FIT_BH]:
(self[NameObject(TA.TOP)],) = args
try: # Prefered to be more robust not only to null parameters
(self[NameObject(TA.TOP)],) = args
except Exception:
(self[NameObject(TA.TOP)],) = (NullObject(),)
elif typ in [TF.FIT_V, TF.FIT_BV]:
(self[NameObject(TA.LEFT)],) = args
try: # Prefered to be more robust not only to null parameters
(self[NameObject(TA.LEFT)],) = args
except Exception:
(self[NameObject(TA.LEFT)],) = (NullObject(),)
elif typ in [TF.FIT, TF.FIT_B]:
pass
else:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_merger.py
Expand Up @@ -288,3 +288,11 @@ def test_sweep_indirect_list_newobj_is_None():

# cleanup
os.remove("tmp-merger-do-not-commit.pdf")


def test_iss1145():
# issue with FitH destination with null param
url = "https://github.com/py-pdf/PyPDF2/files/9164743/file-0.pdf"
name = "iss1145.pdf"
merger = PdfMerger()
merger.append(PdfReader(BytesIO(get_pdf_from_url(url, name=name))))

0 comments on commit 7d825ed

Please sign in to comment.