From 15ae39674e63c67a0421f217f340c1037e85d2bf Mon Sep 17 00:00:00 2001 From: Simon Andrieux Date: Mon, 11 May 2020 17:38:42 +0200 Subject: [PATCH] fix reading from empty buffer when loading .gbr --- Tests/test_file_gbr.py | 7 +++++++ src/PIL/GbrImagePlugin.py | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Tests/test_file_gbr.py b/Tests/test_file_gbr.py index f183390bc..25e624886 100644 --- a/Tests/test_file_gbr.py +++ b/Tests/test_file_gbr.py @@ -15,3 +15,10 @@ def test_gbr_file(): with Image.open("Tests/images/gbr.gbr") as im: with Image.open("Tests/images/gbr.png") as target: assert_image_equal(target, im) + + +def test_multiples_operation(): + with Image.open("Tests/images/gbr.gbr") as im: + rect = (0, 0, 10, 10) + im.crop(rect) + im.crop(rect) diff --git a/src/PIL/GbrImagePlugin.py b/src/PIL/GbrImagePlugin.py index 292de435c..23a7a5c75 100644 --- a/src/PIL/GbrImagePlugin.py +++ b/src/PIL/GbrImagePlugin.py @@ -84,8 +84,9 @@ class GbrImageFile(ImageFile.ImageFile): self._data_size = width * height * color_depth def load(self): - self.im = Image.core.new(self.mode, self.size) - self.frombytes(self.fp.read(self._data_size)) + if not self.im: + self.im = Image.core.new(self.mode, self.size) + self.frombytes(self.fp.read(self._data_size)) #