Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] found 2 bugs when pdf has no /Rotation, viewinfo #17

Open
baslr opened this issue Jul 10, 2023 · 0 comments
Open

[Bug] found 2 bugs when pdf has no /Rotation, viewinfo #17

baslr opened this issue Jul 10, 2023 · 0 comments

Comments

@baslr
Copy link

baslr commented Jul 10, 2023

Hello,

we found 2 bugs in the library.
This line crashes when there is no /Rotation information in the pdf.

rotation = get_rotation(inheritable.Rotate)

And also this line crashes:

mbox, bbox = getrects(inheritable, viewinfo, rotation)

I added try catch and set default but this is just a temporary fix. Especially the defaults for the mbox are totally wrong when the pdf is horizontal oriented.

The company was so kind and generated a sharable pdf which contains the problem.

minimal example:

from io import BytesIO

from pdfrw import PageMerge
from pdfrw import PdfReader

in_file = open("Warenbewegungsschein_Test.pdf", "rb") # opening for [r]eading as [b]inary
data = in_file.read()
raw_pdf = BytesIO(data)
raw_pdf.seek(0)

srcpage = PdfReader(raw_pdf).pages
srcpage = PageMerge() + srcpage[0]

(line numbers may be not correct because of debugging)

python simple_test.py
Traceback (most recent call last):
  File "/home/manuel/dls-pdf-parser/pdf_merger/simple_test.py", line 17, in <module>
    srcpage = PageMerge() + srcpage[0]
  File "/home/manuel/dls-pdf-parser/venv/lib/python3.10/site-packages/pdfrw/pagemerge.py", line 169, in __add__
    self.add(item)
  File "/home/manuel/dls-pdf-parser/venv/lib/python3.10/site-packages/pdfrw/pagemerge.py", line 176, in add
    obj = RectXObj(obj)
  File "/home/manuel/dls-pdf-parser/venv/lib/python3.10/site-packages/pdfrw/pagemerge.py", line 56, in __init__
    base = pagexobj(page, viewinfo)
  File "/home/manuel/dls-pdf-parser/venv/lib/python3.10/site-packages/pdfrw/buildxobj.py", line 300, in pagexobj
    rotate = inheritable.Rotate
  File "/home/manuel/dls-pdf-parser/venv/lib/python3.10/site-packages/pdfrw/objects/pdfdict.py", line 19, in __getattr__
    return self[PdfName(name)]
  File "/home/manuel/dls-pdf-parser/venv/lib/python3.10/site-packages/pdfrw/objects/pdfdict.py", line 25, in __getitem__
    value = mydict[name]
TypeError: string indices must be integers

Warenbewegungsschein_Test.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant