Skip to content

BUG: Expand low-bit samples for images without a filter - #3938

Merged
stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:fix-low-bit-non-flate
Aug 5, 2026
Merged

stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:fix-low-bit-non-flate

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

Follow-up to #3929, which only fixed the FlateDecode path.

Fixes #3367.

The 2/4-bit expansion lived inside _handle_flate, so it only ran for
FlateDecode/RunLengthDecode images. Anything else — an image with no filter
at all, or the LZW/ASCII85 fallback — passed the raw "2bits"/"4bits" mode
straight to Pillow and raised "unrecognized image mode".

Pulled the expansion out into _expand_low_bit_samples() and called it from
the three places that build an image from raw bytes. The Flate path behaves
exactly as before, bits2byte is unchanged.

Added a test that builds an uncompressed 4-bit /DeviceRGB image and checks
it decodes to RGB — it fails on main with the same ValueError you were
seeing.

@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.88%. Comparing base (8b6f6fd) to head (0f8a3c9).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3938   +/-   ##
=======================================
  Coverage   97.88%   97.88%           
=======================================
  Files          57       57           
  Lines       10813    10816    +3     
  Branches     2025     2025           
=======================================
+ Hits        10584    10587    +3     
  Misses        127      127           
  Partials      102      102           

☔ 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.

@stefan6419846 stefan6419846 left a comment

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.

Thanks. I just did a quick test with my example, and it is working correctly now and the output looks correct as well.

@stefan6419846
stefan6419846 merged commit 55bd85c into py-pdf:main Aug 5, 2026
20 checks passed
stefan6419846 added a commit that referenced this pull request Aug 6, 2026
## What's new

### Security (SEC)
- Improve performance of read_until_whitespace (#3947) by @stefan6419846
- Limit CID width range and width count when loading fonts (#3946) by @stefan6419846
- Limit token length for ToUnicode entries (#3944) by @stefan6419846

### Deprecations (DEP)
- Deprecate previously missed inline_images setter as well (#3897) by @stefan6419846

### New Features (ENH)
- Add ActualText tag when we produce RTL appearance stream (#3901) by @PJBrs
- Allow keeping original PDF header in non-incremental clone mode (#3918) by @pctablet505
- AppearanceStream: Add support for RTL appearance streams with Arabic characters (#3831) by @PJBrs
- Add actions base class (#3552) by @j-t-1

### Bug Fixes (BUG)
- Expand low-bit samples for images without a filter (#3938) by @RavSinghChandan
- Decode low-bit DeviceRGB images as RGB instead of palette (#3929) by @RavSinghChandan
- Correctly handle IndirectObject in FlateDecode.decode DecodeParms (#3937) by @stefan6419846

### Documentation (DOC)
- Image and attachment filenames are unsanitized (#3942) by @stefan6419846

### Maintenance (MAINT)
- Update charset mappings (#3935) by @stefan6419846

[Full Changelog](6.14.2...6.15.0)
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.

Image handling: Mode from RGB path will always be overwritten

2 participants