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

floodfill wraps around #4016

Closed
snoopyjc opened this issue Aug 8, 2019 · 3 comments · Fixed by #4017
Closed

floodfill wraps around #4016

snoopyjc opened this issue Aug 8, 2019 · 3 comments · Fixed by #4017
Labels
Bug Any unexpected behavior, until confirmed feature.
Projects

Comments

@snoopyjc
Copy link

snoopyjc commented Aug 8, 2019

The ImageDraw.floodfill code assumes a negative index will raise an IndexError, but python wraps that around to the last element, which is not the desired effect. This causes a floodfill that hits the left side or the top of the image to wrap around to the other side. Code:

                    try:
                        p = pixel[s, t]
                    except (ValueError, IndexError):
                        pass
                    else:

Fix:

                    try:
                        if s < 0 or t < 0:
                            raise IndexError
                        p = pixel[s, t]
                    except (ValueError, IndexError):
                        pass
                    else:
@radarhere
Copy link
Member

Thanks. I've created PR #4017 to resolve this, adjusting your solution slightly.

@radarhere radarhere added the Bug Any unexpected behavior, until confirmed feature. label Aug 9, 2019
@radarhere radarhere added this to Review/QA in Pillow Aug 17, 2019
Pillow automation moved this from Review/QA to Closed Sep 5, 2019
@hugovk
Copy link
Member

hugovk commented Sep 5, 2019

Thanks both, merged!

@snoopyjc
Copy link
Author

snoopyjc commented Sep 6, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any unexpected behavior, until confirmed feature.
Projects
Pillow
  
Closed
Development

Successfully merging a pull request may close this issue.

3 participants