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

BUG: Correctly handle image mode 1 with FlateDecode #2249

Merged
merged 3 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pypdf/_xobj_image_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
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 @@ -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
Loading