Skip to content

Fix IndexError in apply_png_predictor for wide scanlines - #1275

Closed
SAY-5 wants to merge 1 commit into
pdfminer:masterfrom
SAY-5:fix-png-predictor-scanline-width
Closed

Fix IndexError in apply_png_predictor for wide scanlines#1275
SAY-5 wants to merge 1 commit into
pdfminer:masterfrom
SAY-5:fix-png-predictor-scanline-width

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jul 18, 2026

Copy link
Copy Markdown

Pull request

Fixes #1269. apply_png_predictor seeds the prior row with line_above = bytearray(columns), but a scanline is nbytes = colors * columns * bitspercomponent // 8 bytes wide. When that is wider than columns (multiple colors, or 8-bit components), the first scanline with filter type 3 (Average) or 4 (Paeth) indexes line_above[j] past its end and raises IndexError: list index out of range. Seeding it with bytearray(nbytes) gives the spec-mandated full-width zero prior row, matching the width of the raw rows used for every later scanline.

How Has This Been Tested?

Added test_apply_png_predictor_multibyte_pixels in tests/test_utils.py, which decodes a 3-color scanline (6 bytes wide, columns=2) with the Average filter and checks the output. It raises the reported IndexError without the fix and passes with it. The full tests/test_utils.py suite passes and ruff is clean.

Checklist

  • I have read CONTRIBUTING.md.
  • I have added a concise human-readable description of the change to CHANGELOG.md.
  • I have tested that this fix is effective or that this feature works.
  • I have added docstrings to newly created methods and classes.
  • I have updated the README.md and the readthedocs documentation. Or verified that this is not necessary.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@nikolas

nikolas commented Jul 21, 2026

Copy link
Copy Markdown

This is a duplicate of #1271

@SAY-5

SAY-5 commented Jul 26, 2026

Copy link
Copy Markdown
Author

You're right, #1271 has the same fix already in flight. Closing this one in favor of that.

@SAY-5 SAY-5 closed this Jul 26, 2026
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 this pull request may close these issues.

IndexError: list index out of range with dumppdf -at

2 participants