From 0411caba67b8127694be4dabbdedd1dc65d12576 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 1 Sep 2018 17:18:13 +1000 Subject: [PATCH] Catch ValueError when processing the edge of an image --- Tests/test_imagedraw.py | 5 +++++ src/PIL/ImageDraw.py | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 33e7f8477..5f9649a78 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -366,6 +366,11 @@ class TestImageDraw(PillowTestCase): ImageDraw.floodfill(im, (W, H), red) self.assert_image_equal(im, im_floodfill) + # Test filling at the edge of an image + im = Image.new("RGB", (1, 1)) + ImageDraw.floodfill(im, (0, 0), red) + self.assert_image_equal(im, Image.new("RGB", (1, 1), red)) + def test_floodfill_border(self): # floodfill() is experimental diff --git a/src/PIL/ImageDraw.py b/src/PIL/ImageDraw.py index ca8c1d17b..428174784 100644 --- a/src/PIL/ImageDraw.py +++ b/src/PIL/ImageDraw.py @@ -358,7 +358,7 @@ def floodfill(image, xy, value, border=None, thresh=0): for (s, t) in ((x+1, y), (x-1, y), (x, y+1), (x, y-1)): try: p = pixel[s, t] - except IndexError: + except (ValueError, IndexError): pass else: if _color_diff(p, background) <= thresh: @@ -372,7 +372,7 @@ def floodfill(image, xy, value, border=None, thresh=0): for (s, t) in ((x+1, y), (x-1, y), (x, y+1), (x, y-1)): try: p = pixel[s, t] - except IndexError: + except (ValueError, IndexError): pass else: if p != value and p != border: