pymupdf / PyMuPDF

PyMuPDF is a high performance Python library for data extraction, analysis, conversion & manipulation of PDF (and other) documents.
https://pymupdf.readthedocs.io
GNU Affero General Public License v3.0
5.46k stars 513 forks source link

PyMuPDF hangs when iterating over zero page PDF pages backwards #4018

Open C-Saunders opened 17 hours ago

C-Saunders commented 17 hours ago

Description of the bug

PyMuPDF is able to open this PDF, but hangs if I try to iterate over the pages backwards.

How to reproduce the bug

zero_pages.pdf

import pymupdf

pdf = pymupdf.open("...zero_pages.pdf")

# this raises ValueError: bad start page number
for page in pdf.pages():
    print(page.number)

# this hangs forever
for page in pdf.pages(-1, -1):
    print(page.number)

I've tried this on Mac and Linux, and with PyMuPDF versions 1.24.9 and 1.24.13

PyMuPDF version

1.24.13

Operating system

MacOS

Python version

3.11

JorjMcKie commented 16 hours ago

Trivial change fixes this.