-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
Has MCVEA minimal, complete and verifiable example helps a lot to debug / understand feature requestsA minimal, complete and verifiable example helps a lot to debug / understand feature requestsis-bugFrom a users perspective, this is a bug - a violation of the expected behavior with a compliant PDFFrom a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF
Description
This bug reports originates with pspdfutils: See rrthomas/psutils#57.
The command psnup -2 testbook.pdf output.pdf gives an infinite recursion backtrace.
Environment
Ubuntu 22.04.
$ python -m platform
Linux-6.2.0-26-generic-x86_64-with-glibc2.35
$ python -c "import pypdf;print(pypdf.__version__)"
3.15.2Code + PDF
Minimal example:
from pypdf import PdfWriter, PdfReader
reader = PdfReader("testbook.pdf")
writer = PdfWriter("foo.pdf")
width, height = 595, 841
outpage = writer.add_blank_page(width, height)
outpage.merge_page(reader.pages[6])Note in particular: if I replace the last two lines with
outpage = writer.add_page(reader.pages[6])
then it works.
Here is the test file:
Traceback
This is the complete Traceback I see:
$ python test.py
Traceback (most recent call last):
File "/home/rrt/Software/psutils/test.py", line 9, in <module>
outpage.merge_page(reader.pages[6])
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/_page.py", line 1044, in merge_page
self._merge_page(page2, over=over, expand=expand)
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/_page.py", line 1071, in _merge_page
return self._merge_page_writer(
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/_page.py", line 1224, in _merge_page_writer
aa = a.clone(
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/generic/_data_structures.py", line 197, in clone
d__._clone(self, pdf_dest, force_duplicate, ignore_fields)
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/generic/_data_structures.py", line 297, in _clone
v.clone(pdf_dest, force_duplicate, ignore_fields)
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/generic/_data_structures.py", line 197, in clone
d__._clone(self, pdf_dest, force_duplicate, ignore_fields)
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/generic/_data_structures.py", line 297, in _clone
v.clone(pdf_dest, force_duplicate, ignore_fields)
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/generic/_data_structures.py", line 115, in clone
arr.append(data.clone(pdf_dest, force_duplicate, ignore_fields))
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/generic/_base.py", line 295, in clone
obj.clone(pdf_dest, force_duplicate, ignore_fields)
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/generic/_data_structures.py", line 197, in clone
d__._clone(self, pdf_dest, force_duplicate, ignore_fields)
then repeats a lot, before ending:
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/generic/_base.py", line 295, in clone
obj.clone(pdf_dest, force_duplicate, ignore_fields)
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/generic/_data_structures.py", line 197, in clone
d__._clone(self, pdf_dest, force_duplicate, ignore_fields)
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/generic/_data_structures.py", line 297, in _clone
v.clone(pdf_dest, force_duplicate, ignore_fields)
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/generic/_data_structures.py", line 115, in clone
arr.append(data.clone(pdf_dest, force_duplicate, ignore_fields))
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/generic/_data_structures.py", line 197, in clone
d__._clone(self, pdf_dest, force_duplicate, ignore_fields)
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/generic/_data_structures.py", line 297, in _clone
v.clone(pdf_dest, force_duplicate, ignore_fields)
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/generic/_data_structures.py", line 197, in clone
d__._clone(self, pdf_dest, force_duplicate, ignore_fields)
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/generic/_data_structures.py", line 297, in _clone
v.clone(pdf_dest, force_duplicate, ignore_fields)
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/generic/_data_structures.py", line 115, in clone
arr.append(data.clone(pdf_dest, force_duplicate, ignore_fields))
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/generic/_base.py", line 295, in clone
obj.clone(pdf_dest, force_duplicate, ignore_fields)
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/generic/_data_structures.py", line 197, in clone
d__._clone(self, pdf_dest, force_duplicate, ignore_fields)
File "/home/rrt/.local/lib/python3.10/site-packages/pypdf/generic/_data_structures.py", line 289, in _clone
if isinstance(v, StreamObject):
File "/usr/lib/python3.10/typing.py", line 1503, in __instancecheck__
issubclass(instance.__class__, cls)):
File "/usr/lib/python3.10/abc.py", line 123, in __subclasscheck__
return _abc_subclasscheck(cls, subclass)
RecursionError: maximum recursion depth exceeded in comparison
Thanks very much for pypdf!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Has MCVEA minimal, complete and verifiable example helps a lot to debug / understand feature requestsA minimal, complete and verifiable example helps a lot to debug / understand feature requestsis-bugFrom a users perspective, this is a bug - a violation of the expected behavior with a compliant PDFFrom a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF