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

Incorrect handling of FlateDecode with image mode "1" #2248

Closed
stefan6419846 opened this issue Oct 9, 2023 · 0 comments · Fixed by #2249
Closed

Incorrect handling of FlateDecode with image mode "1" #2248

stefan6419846 opened this issue Oct 9, 2023 · 0 comments · Fixed by #2249

Comments

@stefan6419846
Copy link
Collaborator

Extracting /FlateDecode images with an image mode of 1 currently fails, probably due to an invalid range loop.

Let's consider the lookup of b'\x00p\xc0\xff\xff\xff' in RGB mode. This should always create two RGB values for further processing ("high" and "low" for image mode 1), but currently only creates one.

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.3, 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 = 'Prototype-Declaration-VDE4110-HYD-5000-20000-ZSS-DE.pdf'
for index, page in enumerate(PdfReader(path).pages):
    for key in page.images.keys():
        print(key)
        print(page.images[key].indirect_reference)

An example file is this

Traceback

This is the complete traceback I see:

Traceback (most recent call last):
  File "/home/stefan/temp/run.py", line 15, in <module>
    print(page.images[key].indirect_reference)
  File "/home/stefan/temp/venv/lib/python3.9/site-packages/pypdf/_page.py", line 2709, in __getitem__
    return self.get_function(index)
  File "/home/stefan/temp/venv/lib/python3.9/site-packages/pypdf/_page.py", line 558, in _get_image
    return self._get_image(ids, cast(DictionaryObject, xobjs[id[0]]))
  File "/home/stefan/temp/venv/lib/python3.9/site-packages/pypdf/_page.py", line 547, in _get_image
    imgd = _xobj_to_image(cast(DictionaryObject, xobjs[id]))
  File "/home/stefan/temp/venv/lib/python3.9/site-packages/pypdf/filters.py", line 781, in _xobj_to_image
    img, image_format, extension, invert_color = _handle_flate(
  File "/home/stefan/temp/venv/lib/python3.9/site-packages/pypdf/_xobj_image_helpers.py", line 177, in _handle_flate
    [
  File "/home/stefan/temp/venv/lib/python3.9/site-packages/pypdf/_xobj_image_helpers.py", line 179, in <listcomp>
    [
  File "/home/stefan/temp/venv/lib/python3.9/site-packages/pypdf/_xobj_image_helpers.py", line 180, in <listcomp>
    colors_arr[1 if img.getpixel((x, y)) > 127 else 0]
IndexError: list index out of range
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