Skip to content

Form XObject with malformed /BBox crashes extraction (ValueError: not enough values to unpack) #1263

Description

@assinscreedFC

Summary

extract_text (and any layout extraction) raises ValueError: not enough values to unpack (expected 4, got 2) on PDFs that contain a form XObject whose /BBox is not the four-number rectangle required by the spec.

Root cause

In PDFPageInterpreter.do_Do (pdfminer/pdfinterp.py), a form XObject's /BBox is passed straight to begin_figureLTFigure.__init__ (pdfminer/layout.py), which unpacks it with (x, y, w, h) = bbox. A /BBox with a different number of elements (e.g. [0 0]) therefore raises a ValueError and aborts the whole extraction. The length of /BBox is never validated.

Minimal reproduction

A form XObject with /BBox [0 0]:

import io
import pdfminer.high_level

pdf = (
    b"%PDF-1.4\n"
    b"1 0 obj <</Type/Catalog/Pages 2 0 R>> endobj\n"
    b"2 0 obj <</Type/Pages/Kids[3 0 R]/Count 1>> endobj\n"
    b"3 0 obj <</Type/Page/Parent 2 0 R/MediaBox[0 0 200 200]"
    b"/Resources<</XObject<</Fm0 4 0 R>>>>/Contents 5 0 R>> endobj\n"
    b"4 0 obj <</Type/XObject/Subtype/Form/FormType 1/BBox [0 0]"
    b"/Resources<<>>/Length 3>>\nstream\nq Q\nendstream endobj\n"
    b"5 0 obj <</Length 7>>\nstream\n/Fm0 Do\nendstream endobj\n"
    b"trailer<</Root 1 0 R>>\n%%EOF"
)
pdfminer.high_level.extract_text(io.BytesIO(pdf))
# ValueError: not enough values to unpack (expected 4, got 2)

(Real-world PDFs from some generators ship such non-conformant form bboxes; this also surfaces downstream in pdfplumber and tools built on it such as markitdown.)

Expected

A non-conformant /BBox should not crash extraction. In non-STRICT mode the malformed bbox should be tolerated (the rest of the document still extracted); STRICT mode may raise.

Environment

  • pdfminer.six 20251230, Python 3.13

I have a fix + regression test ready and will open a PR referencing this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions