Skip to content

Regression? Spurious error? in insert_pdf in v1.25.4 #4412

@C-Saunders

Description

@C-Saunders

Description of the bug

With v1.25.4, calling insert_pdf sometimes causes an IndexError to be raised, but the resulting object seems fine. If insert_pdf is called a second time with the same source doc, no error is raised.

With v1.25.3 I do not see this error.

How to reproduce the bug

import pymupdf

doc = pymupdf.open("...pdf")
new_doc = pymupdf.open()
new_doc.insert_pdf(doc, from_page=1, to_page=len(doc)-1) # raises IndexError: range object index out of range

len(new_doc) # has the correct number of pages
new_doc.save(...) # saved doc looks fine
import pymupdf

doc = pymupdf.open("...pdf")
new_doc = pymupdf.open()
new_doc.insert_pdf(doc, from_page=1, to_page=1) # raises IndexError: range object index out of range

len(new_doc) # == 1

new_doc_2 = pymupdf.open()
new_doc_2.insert_pdf(doc, from_page=1, to_page=1) # does not raise this time

Unfortunately I've been unable to find a PII-free example to share, but I hoped there might be enough detail here to work from. If I'm able to find a good reproduction I will share it, though!

PyMuPDF version

1.25.4

Operating system

MacOS

Python version

3.11

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions