Fix PICT pixel decoding for 32-bit planar and cicn icons - #14
Open
grub-basket wants to merge 1 commit into
Open
Conversation
Two decoding bugs in pict.py: 1. unpack4() used a 3-plane row stride (y*w*3) in the 4-plane (32-bit ARGB planar) branch, even though the buffer holds numplanes*w*h == 4*w*h bytes with rows 4*w wide. Any packtype-4 PICT with cmpcount==4 decoded with rows sliding out of alignment (scrambled colors/alpha). Use y*w*4 as the row base. 24-bit (3-plane) was already correct. 2. read_cicn() read the black-and-white icon bitmap using the mask bitmap's height (maskbm.height) instead of the B&W icon bitmap's own height. When the two BitMaps have different bounds, the unpacker advanced by the wrong byte count and the following read_colortable() read from the wrong offset, corrupting the palette. Use bwiconbm.height.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two decoding bugs in
pict.py:unpack4()uses a 3-plane row stride (y*w*3) in the 4-plane branch, even though the buffer holdsnumplanes*w*h == 4*w*hbytes with rows4*wwide. Any packtype-4 PICT withcmpcount == 4(32-bit ARGB planar) decodes with rows sliding out of alignment — colors/alpha bleed across rows. 24-bit (3-plane) was already correct.read_cicn()reads the black-and-white icon bitmap using the mask bitmap's height (maskbm.height) instead of the B&W icon's own (bwiconbm.height). When the two BitMaps have different bounds, the unpacker advances by the wrong byte count and the followingread_colortable()reads from the wrong offset, corrupting the palette.Fix
Use
y*w*4as the row base in the 4-plane branch, andbwiconbm.heightfor the B&W icon read.Prepared with Claude Fable 5 (Low effort mode). Automated finding, manually verified — please review before merging.