-
Notifications
You must be signed in to change notification settings - Fork 647
Description
Description of the bug
I am creating a system that will insert text after specific elements on a pdf page.
It does the following operations in order:
- Search for insert location
- Based on text insertion size, determine the shift amount for content below insertion location
- Create a new page, extended vertically by shift amount
- Place the content above the insertion point at the top of the new page, and place the content below it low enough for the text to be written into the space created
- Write the text into the space created
In this process of copying over information to blank pages, show_pdf_page
is used and redactions are used alongside it to prevent invisible data being carried over. When doing this sequence of events too many times (in my case over 8) on the same page (real pdf page, not pymupdf page) apply_redactions
or show_pdf_page
(depending on situations described below) will result in a stack overflow error.
How to reproduce the bug
On my account there is a repository called pymupdf-bug -> https://github.com/anthony-comp/pymupdf-bug
This contains python code and a sample pdf file that will produce the stack overflow issue.
Note that the stack overflow first occurs during apply_redactions()
- if a try/except were to be wrapped around these and have them be ignored with pass
or something similar, the stack overflow will eventually occur during show_pdf_page
later on.
Note that if the loop_count
variable is changed to be 8 or lower, the bug will not occur and the desired output will be generated.
Here is the output:
MuPDF error: exception stack overflow!
Traceback (most recent call last):
File "C:\Users\USERNAME\bug_report.py", line 157, in <module>
main()
File "C:\Users\USERNAME\bug_report.py", line 132, in main
above_page.apply_redactions()
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python310\lib\site-packages\pymupdf\utils.py", line 4241, in apply_redactions
rc = page._apply_redactions(text, images, graphics) # call MuPDF
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python310\lib\site-packages\pymupdf\__init__.py", line 7836, in _apply_redactions
success = mupdf.pdf_redact_page(page.doc(), page, opts)
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python310\lib\site-packages\pymupdf\mupdf.py", line 53155, in pdf_redact_page
return _mupdf.pdf_redact_page(doc, page, opts)
pymupdf.mupdf.FzErrorLimit: code=5: exception stack overflow!
PyMuPDF version
1.25.5
Operating system
Windows
Python version
3.10