Skip to content

Commit

Permalink
BUG: Correctly handle image mode 1 with FlateDecode (#2249)
Browse files Browse the repository at this point in the history
Fixes #2248
  • Loading branch information
stefan6419846 committed Oct 28, 2023
1 parent faa8c68 commit e9241ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pypdf/_xobj_image_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ def bits2byte(data: bytes, size: Tuple[int, int], bits: int) -> bytes:
lookup = None
else:
if img.mode == "1":
colors_arr = [lookup[x - nb : x] for x in range(nb, len(lookup), nb)]
# Two values ("high" and "low").
assert len(lookup) == 2 * nb, len(lookup)
colors_arr = [lookup[:nb], lookup[nb:]]
arr = b"".join(
[
b"".join(
Expand Down
12 changes: 12 additions & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from pypdf.generic import ArrayObject, DictionaryObject, NameObject, NumberObject

from . import get_data_from_url
from .test_encryption import HAS_AES
from .test_images import image_similarity

filter_inputs = (
Expand Down Expand Up @@ -637,3 +638,14 @@ def test_nested_device_n_color_space():
name = "issue2240.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
reader.pages[0].images[0]


@pytest.mark.enable_socket()
@pytest.mark.skipif(not HAS_AES, reason="No AES implementation")
def test_flate_decode_with_image_mode_1():
"""From #2248"""
url = "https://github.com/py-pdf/pypdf/files/12847339/Prototype-Declaration-VDE4110-HYD-5000-20000-ZSS-DE.pdf"
name = "issue2248.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
for image in reader.pages[7].images:
_ = image

0 comments on commit e9241ac

Please sign in to comment.