diff --git a/pypdf/_xobj_image_helpers.py b/pypdf/_xobj_image_helpers.py index bf3c869f7..ebc0d1cea 100644 --- a/pypdf/_xobj_image_helpers.py +++ b/pypdf/_xobj_image_helpers.py @@ -167,7 +167,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( diff --git a/tests/test_filters.py b/tests/test_filters.py index 12819c43b..bcb71e88e 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -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 = ( @@ -628,3 +629,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