Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure palette string matches RGB mode #5549

Merged
merged 2 commits into from Jun 20, 2021
Merged

Conversation

radarhere
Copy link
Member

Resolves #4830

The image from that issue has a BGR;15 palette. So when PngImagePlugin tries to calculate the number of colors to use when saving for show(),

colors = max(min(len(im.palette.getdata()[1]) // 3, 256), 1)

the assumption, that it can divide by 3 because this is RGB, is false.

This PR adds a change to Image, so that when it sets the palette mode to RGB, there is actually RGB data in the palette string.

@radarhere
Copy link
Member Author

The first commit is failing, as another test complains that the palette is now longer than it should be.

This is because I'm calling getpalette(), which has a fixed palette length.

The C layer ImagingPaletteInstance doesn't actually have a palette length, so instead, I've returned the length from putpalette and used that in Python to trim the output.

@radarhere
Copy link
Member Author

The CI Fuzz failure is related. See https://github.com/radarhere/Pillow/actions/runs/951376400 from just a comment change in C.

@hugovk
Copy link
Member

hugovk commented Jun 20, 2021

The CI Fuzz failure is related. See radarhere/Pillow/actions/runs/951376400 from just a comment change in C.

You mean unrelated?

@radarhere
Copy link
Member Author

Yes, unrelated :p

@hugovk hugovk merged commit 53b51e1 into python-pillow:master Jun 20, 2021
@radarhere radarhere deleted the palette branch June 20, 2021 12:45
@radarhere
Copy link
Member Author

I've created google/oss-fuzz#5950 to fix the CI Fuzz failure.

@radarhere
Copy link
Member Author

PR has been merged, and CI Fuzz is working again.

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.

PIL doesn't seem to handle the color map correctly in some color indexed TGA files
2 participants