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

Raise ValueError during filter operation as well #91

Merged

Conversation

radarhere
Copy link

Suggestion for python-pillow#6874

Other ways to trigger the problem are

import numpy as np
from PIL import Image, ImageFilter

img = Image.fromarray(np.ones([100, 100, 3], dtype='uint8'))
blur = ImageFilter.BoxBlur(2)
blur.radius = -2
img = img.filter(blur)

You could also abuse getdata() to access the C api directly, but that's less legitimate.

import numpy as np
from PIL import Image, ImageFilter

img = Image.fromarray(np.ones([100, 100, 3], dtype='uint8'))
img = img.getdata().box_blur(-2)

This PR raises an error from C if a negative radius is used after initialisation of the filter to prevent those scenarios.

@hugovk
Copy link
Owner

hugovk commented Jan 11, 2023

Thanks!

Funny thing is I also tried out this very same C change and with that first test case, but mistakenly thought it was being caught by just the Python change 🙃

@hugovk hugovk merged commit d504d2a into hugovk:invalid-box-blur-filter Jan 11, 2023
@radarhere radarhere deleted the invalid-box-blur-filter branch January 11, 2023 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants