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

ROB: Relax flate decoding for too many lookup values #2331

Merged
merged 5 commits into from
Dec 10, 2023
Merged
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion pypdf/_xobj_image_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,14 @@
else:
if img.mode == "1":
# Two values ("high" and "low").
assert len(lookup) == 2 * nb, len(lookup)
if len(lookup) != 2 * nb:
if len(lookup) < 2 * nb:
raise PdfReadError(f"Not enough lookup values: Expected {2 * nb}, got {len(lookup)}.")
logger_warning(

Check warning on line 201 in pypdf/_xobj_image_helpers.py

View check run for this annotation

Codecov / codecov/patch

pypdf/_xobj_image_helpers.py#L200-L201

Added lines #L200 - L201 were not covered by tests
f"Expected {2 * nb} lookup values, got {len(lookup)}. Ignoring trailing ones.",
__name__,
)
stefan6419846 marked this conversation as resolved.
Show resolved Hide resolved
lookup = lookup[:2 * nb]

Check warning on line 205 in pypdf/_xobj_image_helpers.py

View check run for this annotation

Codecov / codecov/patch

pypdf/_xobj_image_helpers.py#L205

Added line #L205 was not covered by tests
colors_arr = [lookup[:nb], lookup[nb:]]
arr = b"".join(
[
Expand Down
Loading