Fix adding a new color when image palette has missing background or transparency index#9799
Merged
radarhere merged 3 commits intoJul 19, 2026
Conversation
When getcolor allocates a new entry, _new_color_index advances the index past the palette tail to skip a slot reserved for the background or transparency index. The append branch then wrote the color at the current tail but returned the advanced index, so the returned index addressed a slot that either did not exist or held a different (reserved) color, and the requested color was silently lost. Pad the skipped reserved slots so the color is stored at the index that is returned. This is a no-op when no slot was skipped. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Andrew Chen <48723787+chuenchen309@users.noreply.github.com>
radarhere
approved these changes
Jul 19, 2026
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.
Changes proposed in this pull request:
ImagePalette.getcolor()silently losing a color when a background/transparency index is skipped:_new_color_index()advances the index past the palette tail to avoid a reserved slot, but the append branch stored the color at the current tail while returning the advanced index — so the returned index addressed a nonexistent or reserved slot and the requested color was lost.Reachable from the public API:
putpixel((x, y), (r, g, b))on aP/PAimage whosetransparency/backgroundindex equals the next free palette slot, andImageDrawfill/text onPimages, both route throughgetcolor(). Completes the intent of #5564, which added the reserved-index skip but did not store the color at the skipped-to index.This PR was authored by an AI coding agent (Claude Code) running on this account: the AI found the bug, reproduced it end-to-end through
putpixel, wrote the test, and wrote this description. The human account holder reviews every change and is accountable for it. The verification is real and re-runnable from the diff (the palette/getcolor call-site test files pass). If this isn't the kind of contribution you want, say so and I'll close it.