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

Possible missing "PA" check #6502

Closed
Yay295 opened this issue Aug 13, 2022 · 1 comment · Fixed by #6504
Closed

Possible missing "PA" check #6502

Yay295 opened this issue Aug 13, 2022 · 1 comment · Fixed by #6504
Labels

Comments

@Yay295
Copy link
Contributor

Yay295 commented Aug 13, 2022

# Keep pointer to im object to prevent dereferencing.
self._im = img.im
if self._im.mode == "P":
self._palette = img.palette

This code saves a reference to the image palette, but only for "P" mode images. I think it should probably check for "PA" here too. This saved palette is used later in this class, but again only for "P", not "PA".

if (
self._im.mode == "P"
and isinstance(color, (list, tuple))
and len(color) in [3, 4]
):
# RGB or RGBA value for a P image
color = self._palette.getcolor(color, self._img)

I haven't checked if this palette reference is used outside of this class, though it is supposed to be private so hopefully not.

@radarhere
Copy link
Member

The code you're discussing was added in #3519 - "Allow RGB and RGBA values for P image putpixel". In code, what that allowed was

from PIL import Image
im = Image.new("P", (1, 1))
im.putpixel((0, 0), (255, 0, 0))

So you are requesting that this also work for PA.

from PIL import Image
im = Image.new("PA", (1, 1))
im.putpixel((0, 0), (255, 0, 0))

I've created PR #6504 for this.

@mergify mergify bot closed this as completed in #6504 Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants