Wrong Handling of Reference Count of "None" Object · Issue #2146 · pymupdf/PyMuPDF (original) (raw)
I'm iterating all xrefs found in the pdf to determine their "content":
document = fitz.Document(fileName)
nonImageXrefs = []
imageXrefs = []
allXrefsLength = document.xref_length()
for xref in range(1, allXrefsLength):
if document.xref_get_key(xref, "Subtype")[1] == "/Image":
if document.extract_image(xref):
imageXrefs.append(xref)
else:
rawData = document.xref_stream_raw(xref)
if rawData is None or len(rawData) == 0:
print("xref {0} is neither image nor deflatable stream".format(xref))
else:
nonImageXrefs.append(xref)
And when there are lot's of such actions I'm getting following error:
Fatal Python error: none_dealloc: deallocating None
Python runtime state: initialized
Current thread 0x00002b44 (most recent call first):
File "C:\Program Files\Python\lib\pdfUtils.py", line 592 in optimizeWithPyMuPdf
File "C:\Users\Alex\PycharmProjects\pdfOptimizer\pdf_opt.py", line 8 in <module>
Extension modules: fitz._fitz, zopfli.zopfli, PIL._imaging (total: 3)
Process finished with exit code -1073740791 (0xC0000409)
Line 592 is rawData = document.xref_stream_raw(xref)
This happens in random place of xrefs list, but usual counter is between 11000-13000
I'm using Windows 10, python 3.10 x64, pyMuPDF 1.21.1 installed by pip.
Attached sample file, but as far as I can see it is not caused by some specific file.
eos6d-mk2-im2-en1.pdf