Skip to content

Regression in 1.28.x: get_pixmap() and get_text() hang at 100% CPU on a specific PDF; works in 1.27.2.3 #5082

Description

@nyhtn

Description of the bug

PyMuPDF 1.28.2 hangs indefinitely with approximately 100% CPU usage when processing the first page of a specific publicly available PDF.

Both Page.get_pixmap() and Page.get_text() are affected.

The same PDF works correctly with PyMuPDF 1.27.2.3.

This appears to be a regression introduced between 1.27.2.3 and 1.28.x.

Public PDF:

https://www.city.toyota.aichi.jp/_res/projects/default_project/_page_/001/057/466/01.pdf

PDF size:

2,983,626 bytes

How to reproduce

import urllib.request
import pymupdf

url = "https://www.city.toyota.aichi.jp/_res/projects/default_project/_page_/001/057/466/01.pdf"

with urllib.request.urlopen(url, timeout=30) as response:
    data = response.read()

print("downloaded:", len(data), flush=True)

doc = pymupdf.open(stream=data, filetype="pdf")
page = doc[0]

print("START get_pixmap", flush=True)
page.get_pixmap()
print("END get_pixmap", flush=True)

Run with a timeout, for example:

timeout 10s python repro.py
echo $?

With PyMuPDF 1.28.2, the output is:

downloaded: 2983626
START get_pixmap

The process then consumes approximately 100% CPU and does not return.

The timeout exits with code 124.

get_text() behaves the same way:

page.get_text()

and:

page.get_text("text", flags=0)

Both hang on page 1.

Additional investigation

Page.clean_contents() itself completes successfully:

page.clean_contents()
print("clean complete", flush=True)

page.get_text()

Output:

clean complete

but the subsequent get_text() still hangs.

Therefore, the issue does not appear to be caused only by multiple /Contents streams or text extraction flags.

Rendering is also affected because get_pixmap() hangs, so the issue appears to occur while processing the page contents rather than only during structured text extraction.

Version comparison

PyMuPDF 1.28.2 / MuPDF 1.28.2

PyMuPDF 1.28.2: Python bindings for the MuPDF 1.28.2 library.
Python 3.12 running on linux (64-bit).

Results on page 1:

page.get_pixmap()              -> hangs / high CPU
page.get_text("text", flags=0) -> hangs / high CPU
page.get_text()                -> hangs / high CPU

PyMuPDF 1.27.2.3 / MuPDF 1.27.2

PyMuPDF 1.27.2.3: Python bindings for the MuPDF 1.27.2 library.
Python 3.12 running on linux (64-bit).

The same PDF completes normally.

Example text extraction timings:

PAGE_START 1
PAGE_END 1 elapsed=0.036 chars=959
PAGE_START 2
PAGE_END 2 elapsed=0.014 chars=595
PAGE_START 3
PAGE_END 3 elapsed=0.009 chars=834
PAGE_START 4
PAGE_END 4 elapsed=0.011 chars=740
PAGE_START 5
PAGE_END 5 elapsed=0.007 chars=536
PAGE_START 6
PAGE_END 6 elapsed=0.019 chars=762
PAGE_START 7
PAGE_END 7 elapsed=0.014 chars=840
PAGE_START 8
PAGE_END 8 elapsed=0.019 chars=1449
DONE

Environment

  • OS: Linux x86_64
  • Python: 3.12
  • Installation: official pip wheel
  • PyMuPDF: 1.28.2
  • MuPDF: 1.28.2
  • Wheel: pymupdf-1.28.2-cp310-abi3-manylinux_2_28_x86_64.whl

Expected behavior

The page should render and text extraction should complete as it does with PyMuPDF 1.27.2.3.

Actual behavior

On PyMuPDF 1.28.2, processing page 1 enters a high-CPU state and does not return.

Related issues

The symptoms look similar to previous upstream hangs such as #3125, #3357, #3430, and #4435, but this appears to be a new regression affecting the 1.28.x series and the PDF above.

How to reproduce the bug

I can provide additional diagnostics or test a patched version if needed. Please let me know if there is anything else I can check on my side.

PyMuPDF version

1.28.2

Operating system

Linux

Python version

3.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    upstream bugbug outside this package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions