Skip to content

ROB: Clarify CMYK comment and detect image format from Pillow instead of guessing - #3902

Open
BiswasNehaa wants to merge 5 commits into
py-pdf:mainfrom
BiswasNehaa:fix-3869-image-xobject-comments
Open

ROB: Clarify CMYK comment and detect image format from Pillow instead of guessing#3902
BiswasNehaa wants to merge 5 commits into
py-pdf:mainfrom
BiswasNehaa:fix-3869-image-xobject-comments

Conversation

@BiswasNehaa

Copy link
Copy Markdown

This covers two of three items in #3869 (CMYK comment + LZW/ASCII85 logic ). Skipped the ICC one.

CMYK: The old comment there pointed to a closed pair with no information. Pillow only got Native CMYK Palette support in v10.1.0, pypdf supports back to 8.0 .0 so the work around stays.

LZW/ASCII85: switched to opening the image first and trusting Pillow's actual detected format, instead of guessing from the filter type ...this is what j-t-1 suggested in the issue thread. Kept the old guess as a fallback for when Pillow can't read it at all.

tested: ran the image test suite, same pass rate as before my change; checked the two real fixture PDFs that hit this code give identical output before/after.

Used Claude to help investigate the Pillow version history and verify the diff.

@BiswasNehaa BiswasNehaa changed the title Clarify stale comments in image XObject handling (#3869) ROB: Clarify CMYK comment and detect image format from Pillow instead of guessing Jun 26, 2026
@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.91%. Comparing base (2b60c99) to head (6bd2c99).
⚠️ Report is 24 commits behind head on main.

Files with missing lines Patch % Lines
pypdf/generic/_image_xobject.py 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3902      +/-   ##
==========================================
- Coverage   97.93%   97.91%   -0.02%     
==========================================
  Files          57       57              
  Lines       11002    11003       +1     
  Branches     2058     2058              
==========================================
- Hits        10775    10774       -1     
- Misses        126      128       +2     
  Partials      101      101              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@BiswasNehaa
BiswasNehaa force-pushed the fix-3869-image-xobject-comments branch from 6f2f50c to 81c4851 Compare June 26, 2026 06:47
Comment thread pypdf/generic/_image_xobject.py
# (in which case it is interpreted as raw, undecoded pixel data).
try:
img = Image.open(BytesIO(data), formats=("TIFF", "PNG"))
image_format = cast(str, img.format)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines are never executed, thus either indicating an issue in your logic or incomplete test data. Please check.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found it — a bad merge conflict resolution had dropped the entire except UnidentifiedImageError: body, which caused a syntax error and explains both the coverage gap and the failing CI. Fixed and pushed; the fallback logic is restored and tests pass locally now.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still got two missing lines in coverage, which indicates something is still going wrong (although the Codecov details page is unable to show any file details at the moment, which seems to be a recurring problem on their side).

Comment thread pypdf/generic/_image_xobject.py
# (in which case it is interpreted as raw, undecoded pixel data).
try:
img = Image.open(BytesIO(data), formats=("TIFF", "PNG"))
image_format = cast(str, img.format)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still got two missing lines in coverage, which indicates something is still going wrong (although the Codecov details page is unable to show any file details at the moment, which seems to be a recurring problem on their side).

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.

2 participants