Skip to content

IndexError in _get_imagemode on Empty ColorSpace Array #3499

@tylzh97

Description

@tylzh97

Summary

The _get_imagemode function directly indexes the first element of the /ColorSpace array without checking if the array is empty. When processing a crafted XObject with an empty colorspace (colorspace_empty.pdf), this triggers an IndexError and aborts the entire page parsing.

Reproduction

from pypdf import PdfReader

reader = PdfReader(open("poc.pdf", "rb"))
page = reader.pages[0]
page.images[0]

Traceback

Traceback (most recent call last):
  ...
  File "pypdf/_xobj_image_helpers.py", line 67, in _get_imagemode
    elif color_space[0].startswith("/Cal"):  # /CalRGB and /CalGray
IndexError: list index out of range

Suggested Fix

  • Check if the list is empty before accessing color_space[0]

poc.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    is-robustness-issueFrom a users perspective, this is about robustnessworkflow-imagesFrom a users perspective, image handling is the affected feature/workflow

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions