diff --git a/PIL/Image.py b/PIL/Image.py index 368186f81..3f8a49e6f 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -1544,7 +1544,7 @@ class Image(object): size = tuple(size) if self.size == size: - return self._new(self.im) + return self.copy() if self.mode in ("1", "P"): resample = NEAREST diff --git a/Tests/test_image_resample.py b/Tests/test_image_resample.py index fb439579c..ebc1ac6e4 100644 --- a/Tests/test_image_resample.py +++ b/Tests/test_image_resample.py @@ -24,6 +24,15 @@ class TestImagingResampleVulnerability(PillowTestCase): with self.assertRaises(ValueError): im.resize((100, -100)) + def test_modify_after_resizing(self): + im = hopper('RGB') + # get copy with same size + copy = im.resize(im.size) + # some in-place operation + copy.paste('black', (0, 0, im.width // 2, im.height // 2)) + # image should be different + self.assertNotEqual(im.tobytes(), copy.tobytes()) + class TestImagingCoreResampleAccuracy(PillowTestCase): def make_case(self, mode, size, color):