Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Unhashable type 'ArrayObject'" when extracting images with nested color space definition #2240

Closed
stefan6419846 opened this issue Oct 5, 2023 · 0 comments · Fixed by #2241

Comments

@stefan6419846
Copy link
Collaborator

When extracting the images from a PDF file, it seems like a /DeviceN color space contains a nested /ICCBased color space definition, which is not supported at the moment:

# Initial `color_space`.
['/DeviceN', ['/HKS 44 K', '/Magenta', '/Yellow', '/Black'], IndirectObject(7, 0, 140608935739344), IndirectObject(11, 0, 140608935739344), IndirectObject(12, 0, 140608935739344)]
# Retrieved `color_space`.
['/ICCBased', IndirectObject(8, 0, 140608935739344)]

Environment

Which environment were you using when you encountered the problem?

$ python -m platform
Linux-5.14.21-150400.24.84-default-x86_64-with-glibc2.31

$ python -c "import pypdf;print(pypdf._debug_versions)"
pypdf==3.16.2, crypt_provider=('pycryptodome', '3.18.0'), PIL=10.0.0

Code + PDF

This is a minimal, complete example that shows the issue:

from pypdf import PdfReader


path = 'out.pdf'
for index, page in enumerate(PdfReader(path).pages):
    print(index, page)
    for key in page.images.keys():
        print(key)
        print(page.images[key].indirect_reference)

The corresponding file is out1.pdf

Traceback

This is the complete traceback I see:

Traceback (most recent call last):
  File "/home/stefan/tmp/run.py", line 12, in <module>
    print(page.images[key].indirect_reference)
  File "/home/stefan/tmp/venv/lib/python3.9/site-packages/pypdf/_page.py", line 2683, in __getitem__
    return self.get_function(index)
  File "/home/stefan/tmp/venv/lib/python3.9/site-packages/pypdf/_page.py", line 555, in _get_image
    return self._get_image(ids, cast(DictionaryObject, xobjs[id[0]]))
  File "/home/stefan/tmp/venv/lib/python3.9/site-packages/pypdf/_page.py", line 544, in _get_image
    imgd = _xobj_to_image(cast(DictionaryObject, xobjs[id]))
  File "/home/stefan/tmp/venv/lib/python3.9/site-packages/pypdf/filters.py", line 761, in _xobj_to_image
    mode, invert_color = _get_imagemode(
  File "/home/stefan/tmp/venv/lib/python3.9/site-packages/pypdf/_xobj_image_helpers.py", line 98, in _get_imagemode
    mode_map.get(color_space)  # type: ignore
TypeError: unhashable type: 'ArrayObject'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant