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
Summary
The
_get_imagemodefunction directly indexes the first element of the/ColorSpacearray without checking if the array is empty. When processing a crafted XObject with an empty colorspace (colorspace_empty.pdf), this triggers anIndexErrorand aborts the entire page parsing.Reproduction
Traceback
Suggested Fix
color_space[0]poc.zip