Skip to content

Segmentation fault in Page.find_tables(use_layout=True) after importing pymupdf4llm #5188

Open

Description

@freinque

Description of the bug

Description
Calling page.find_tables(use_layout=True) on the first page of the attached PDF causes a native segmentation fault. The crash reproduces in a standalone Python process, outside pytest, the debugger, and application threading.

Importing pymupdf4llm is significant: layout was inactive before this import and active afterward in my environment.

Environment

Linux, 64-bit
Python 3.13.16, GCC 14.2.0
PyMuPDF 1.28.2 / MuPDF 1.28.2
PyMuPDF4LLM: 1.28.2

Minimal Reproduction

import faulthandler
import pymupdf
import pymupdf4llm

faulthandler.enable()

print(pymupdf.__doc__, flush=True)

with pymupdf.open("data/protocols/lung_cancer_ctDNA_protocol.pdf") as document:
    page = document[0]
    print("Calling find_tables with layout enabled", flush=True)
    tables = page.find_tables(use_layout=True)
    print(len(tables.tables), flush=True)

Expected Behavior
Table detection completes, or raises a Python exception, without crashing the process.

Actual Behavior

Fatal Python error: Segmentation fault

... pymupdf/extra.py, line 195 in page_get_textpage
... pymupdf/__init__.py, line 10154 in _get_textpage
... pymupdf/__init__.py, line 12356 in get_textpage
... pymupdf/layout/pymupdf_util_base.py, line 465 in create_stext_page
... pymupdf/layout/pymupdf_util_base.py, line 542 in extract_base_elements
... pymupdf/layout/pymupdf_util.py, line 53 in create_input_data_from_page
... pymupdf/layout/onnx/BoxRFDGNN.py, line 928 in predict
... pymupdf/layout/MultiProcessWrapper.py, line 156 in predict
... pymupdf/layout/__init__.py, line 20 in _get_layout
... pymupdf/__init__.py, line 10989 in get_layout
... pymupdf/table.py, line 2942 in find_tables
... pymupdf/__init__.py, line 11571 in find_tables

Segmentation fault (core dumped)

Comparison Results
Each operation was tested in a separate process:

Plain text extraction succeeds: 2,412 characters.
find_tables(use_layout=True) segfaults.
find_tables(use_layout=False) succeeds and detects one table.
A manually printed PDF from the same source document processes successfully.

Attached PDF Details
The failing PDF was exported from Word format through LibreOffice’s writer_pdf_Export:

Producer: LibreOffice 25.2.3.2 (X86_64) / LibreOffice Community
PDF 1.7, 20 pages
Failing page: index 0, dimensions 612 × 792 points
SHA-256: dc648decae17054d9c1775a5286db6e3f67e2b08385f83712608a313d8557c3f
I’m attaching both failing and passing PDFs for comparison ("_printed"). The export difference appears to trigger the crash, but I have not established that the failing PDF is malformed.

lung_cancer_ctDNA_protocol_printed.pdf
lung_cancer_ctDNA_protocol.pdf

How to reproduce the bug

Minimal Reproduction

import faulthandler
import pymupdf
import pymupdf4llm

faulthandler.enable()

print(pymupdf.__doc__, flush=True)

with pymupdf.open("data/protocols/lung_cancer_ctDNA_protocol.pdf") as document:
    page = document[0]
    print("Calling find_tables with layout enabled", flush=True)
    tables = page.find_tables(use_layout=True)
    print(len(tables.tables), flush=True)

Expected Behavior
Table detection completes, or raises a Python exception, without crashing the process.

Actual Behavior

Fatal Python error: Segmentation fault

... pymupdf/extra.py, line 195 in page_get_textpage
... pymupdf/__init__.py, line 10154 in _get_textpage
... pymupdf/__init__.py, line 12356 in get_textpage
... pymupdf/layout/pymupdf_util_base.py, line 465 in create_stext_page
... pymupdf/layout/pymupdf_util_base.py, line 542 in extract_base_elements
... pymupdf/layout/pymupdf_util.py, line 53 in create_input_data_from_page
... pymupdf/layout/onnx/BoxRFDGNN.py, line 928 in predict
... pymupdf/layout/MultiProcessWrapper.py, line 156 in predict
... pymupdf/layout/__init__.py, line 20 in _get_layout
... pymupdf/__init__.py, line 10989 in get_layout
... pymupdf/table.py, line 2942 in find_tables
... pymupdf/__init__.py, line 11571 in find_tables

Segmentation fault (core dumped)

PyMuPDF version

1.28.2

Operating system

Linux

Python version

3.13

Activity

  1. JorjMcKie commented on Oct 18, 2026

    @JorjMcKie
    Collaborator

    Thanks for the submission. Reproduced the problem.
    @veget-able - what do you think?

  2. JorjMcKie commented on Oct 18, 2026

    @JorjMcKie
    Collaborator

    @veget-able -
    I did a few first checks: the crash is not inside page.find_tables() but happens already when calling the layout module i.e. page.get_layout().
    (One of) the difference(s) between pages 0 of both documents is the use of /StructParents 0: it is present in the failing case only.
    When removing this PDF key, the crash will not occur.
    So, this will crash:

    <<
      /Type /Page
      /Parent 752 0 R
      /Resources 774 0 R
      /MediaBox [ 0 0 612 792 ]
      /Tabs /S
      /StructParents 0
      /Contents 2 0 R
    >>
    

    And this will work:

    <<
      /Type /Page
      /Parent 752 0 R
      /Resources 774 0 R
      /MediaBox [ 0 0 612 792 ]
      /Tabs /S
      /StructParents null   # this represents the 'None' object in PDF
      /Contents 2 0 R
    >>
    
  3. JorjMcKie commented on Oct 18, 2026

    @JorjMcKie
    Collaborator

    This appears to be a MuPDF problem. Forwarding to their issue system.

    Link to Bugzilla Issue: https://bugs.ghostscript.com/show_bug.cgi?id=709841

  4. self-assigned this
    on Oct 18, 2026
  5. JorjMcKie commented on Nov 5, 2026

    @JorjMcKie
    Collaborator

    @alexsukhrin please open a separate issue with this and remove your post here.
    In the new issue, please provide a reproducing PDF example and the script you are using to reproduce. We are unable to deal with the problem otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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