diff --git a/src/__init__.py b/src/__init__.py index 915630123..a6b2ef3ca 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -17002,8 +17002,10 @@ def JM_quad_from_py(r): return mupdf.fz_quad_from_rect(JM_rect_from_py(r)) for i in range(4): + if i >= len(r): + return q # invalid: cancel the rest obj = r[i] # next point item - if not obj.m_internal or not PySequence_Check(obj) or PySequence_Size(obj) != 2: + if not PySequence_Check(obj) or PySequence_Size(obj) != 2: return q # invalid: cancel the rest p[i].x = JM_FLOAT_ITEM(obj, 0) diff --git a/tests/resources/mupdf_explored.pdf b/tests/resources/mupdf_explored.pdf new file mode 100644 index 000000000..6eff969bd Binary files /dev/null and b/tests/resources/mupdf_explored.pdf differ diff --git a/tests/test_annots.py b/tests/test_annots.py index b82ba9ff5..419054866 100644 --- a/tests/test_annots.py +++ b/tests/test_annots.py @@ -224,3 +224,21 @@ def test_2270(): assert textBox.get_textbox(textBox.rect) == 'abc123' assert textBox.info['content'] == 'abc123' +def test_2934_add_redact_annot(): + ''' + Test fix for bug mentioned in #2934. + ''' + path = os.path.abspath(f'{__file__}/../../tests/resources/mupdf_explored.pdf') + with open(path, 'rb') as f: + data = f.read() + doc = fitz.Document(stream=data) + print(f'Is PDF: {doc.is_pdf}') + print(f'Number of pages: {doc.page_count}') + + import json + page=doc[0] + page_json_str =doc[0].get_text("json") + page_json_data = json.loads(page_json_str) + span=page_json_data.get("blocks")[0].get("lines")[0].get("spans")[0] + page.add_redact_annot(span["bbox"], text="") + page.apply_redactions()