Skip to content

IndexError in prepare_element for PictureItem with non-empty prov but no embedded image (charts in PPTX) #3867

Description

@kickrunner

Bug

Follow-up to #2390 / #2401. The fix in #2401 only guards the case where a PictureItem has no embedded image and empty provenance (len(element.prov) == 0). It does not cover the case of a PictureItem that has provenance but no embedded image — which is exactly what happens for native chart objects in PPTX (and presumably DOCX/XLSX) files.

In that case, BaseItemAndImageEnrichmentModel.prepare_element still falls through to the page-cropping branch:

page_ix = element_prov.page_no - conv_res.pages[0].page_no
cropped_image = conv_res.pages[page_ix].get_image(...)

Since SimplePipeline (used for PPTX/DOCX/HTML/XLSX) never populates conv_res.pages, this raises IndexError: list index out of range, which BasePipeline.execute wraps into RuntimeError: Pipeline SimplePipeline failed, failing the entire conversion.

Steps to reproduce

Minimal repro — a PPTX with a single native chart shape (no embedded raster image), converted with do_picture_classification=True (also reproducible with do_picture_description=True):

from docling.document_converter import DocumentConverter, PowerpointFormatOption
from docling.datamodel.base_models import InputFormat
from docling.datamodel.pipeline_options import ConvertPipelineOptions
from docling.pipeline.simple_pipeline import SimplePipeline

opts = ConvertPipelineOptions()
opts.do_picture_classification = True

fmt = {InputFormat.PPTX: PowerpointFormatOption(pipeline_cls=SimplePipeline, pipeline_options=opts)}
converter = DocumentConverter(format_options=fmt)
result = converter.convert("minimal_chart_repro.pptx", raises_on_error=True)

Attached: minimal_chart_repro.pptx — generated with python-pptx, containing a single pie chart shape and no other content.

Error Output

Traceback (most recent call last):
  ...
  File ".../docling/models/base_model.py", line 204, in prepare_element
    page_ix = element_prov.page_no - conv_res.pages[0].page_no
                                     ~~~~~~~~~~~~~~^^^
IndexError: list index out of range

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  ...
  File ".../docling/pipeline/base_pipeline.py", line 98, in execute
    raise RuntimeError(f"Pipeline {self.__class__.__name__} failed") from e
RuntimeError: Pipeline SimplePipeline failed

Root cause

DocumentPictureClassifier.is_processable (and other BaseItemAndImageEnrichmentModel subclasses) accept any PictureItem. For chart shapes converted from PPTX, Docling assigns non-empty prov (page number + bbox), but there is no embedded image, since chart shapes are native XML chart objects, not raster images. The #2401 fix only skips elements with empty prov; elements with non-empty prov but no image still hit the conv_res.pages[0] crop path, which is empty for SimplePipeline.

Suggested fix

Guard on conv_res.pages being empty (or check isinstance(self, ...) for pipelines that never populate pages) before attempting the page crop, in addition to the existing embedded-image check, e.g.:

if isinstance(element, PictureItem):
    embedded_im = element.get_image(conv_res.document)
    if embedded_im is not None:
        return ItemAndImageEnrichmentElement(item=element, image=embedded_im)
    elif len(element.prov) == 0 or not conv_res.pages:
        return None

Docling version

docling-slim: 2.114.0

Python version

Python 3.12

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