Skip to content

BUG: KeyError: '/Alternate' #1893

@MartinThoma

Description

@MartinThoma

Replace this: What happened? What were you trying to achieve?

Environment

Which environment were you using when you encountered the problem?

$ python -m platform
Linux-5.4.0-150-generic-x86_64-with-glibc2.31

$ python -c "import pypdf;print(pypdf.__version__)"
3.10.0

Code + PDF

See in test_reader.py:

@pytest.mark.enable_socket()
@pytest.mark.xfail(reason="Raises KeyError: '/Alternate'")
def test_read_images():
    url = "https://www.selbst.de/paidcontent/dl/64733/72916"
    name = "selbst.72916.pdf"
    reader = PdfReader(BytesIO(get_pdf_from_url(url, name=name)))
    page = reader.pages[0]
    for _ in page.images:
        pass

Traceback

Traceback (most recent call last):
  File "/home/moose/main.py", line 10, in <module>
    for img in page.images:
  File "/home/moose/Github/py-pdf/pypdf/pypdf/_page.py", line 2499, in __iter__
    yield self[i]
  File "/home/moose/Github/py-pdf/pypdf/pypdf/_page.py", line 2495, in __getitem__
    return self.get_function(lst[index])
  File "/home/moose/Github/py-pdf/pypdf/pypdf/_page.py", line 522, in _get_image
    imgd = _xobj_to_image(cast(DictionaryObject, xobjs[id]))
  File "/home/moose/Github/py-pdf/pypdf/pypdf/filters.py", line 730, in _xobj_to_image
    mode = _get_imagemode(
  File "/home/moose/Github/py-pdf/pypdf/pypdf/filters.py", line 664, in _get_imagemode
    color_space = color_space[1].get_object()["/Alternate"]
  File "/home/moose/Github/py-pdf/pypdf/pypdf/generic/_data_structures.py", line 290, in __getitem__
    return dict.__getitem__(self, key).get_object()
KeyError: '/Alternate'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Has MCVEA minimal, complete and verifiable example helps a lot to debug / understand feature requestsis-bugFrom a users perspective, this is a bug - a violation of the expected behavior with a compliant PDFkey-errorCould be a bug, but also a robustness issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions