-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
is-robustness-issueFrom a users perspective, this is about robustnessFrom a users perspective, this is about robustnessworkflow-imagesFrom a users perspective, image handling is the affected feature/workflowFrom a users perspective, image handling is the affected feature/workflow
Description
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]
Metadata
Metadata
Assignees
Labels
is-robustness-issueFrom a users perspective, this is about robustnessFrom a users perspective, this is about robustnessworkflow-imagesFrom a users perspective, image handling is the affected feature/workflowFrom a users perspective, image handling is the affected feature/workflow