Skip to content

Commit 91f115b

Browse files
committed
Fixed im.frombytes() for images with a zero dimension
1 parent 5071692 commit 91f115b

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

Tests/test_image.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,9 @@ def test_zero_tobytes(self, size):
910910
def test_zero_frombytes(self, size):
911911
Image.frombytes("RGB", size, b"")
912912

913+
im = Image.new("RGB", size)
914+
im.frombytes(b"")
915+
913916
def test_has_transparency_data(self):
914917
for mode in ("1", "L", "P", "RGB"):
915918
im = Image.new(mode, (1, 1))

src/PIL/Image.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,9 @@ def frombytes(self, data, decoder_name="raw", *args):
791791
but loads data into this image instead of creating a new image object.
792792
"""
793793

794+
if self.width == 0 or self.height == 0:
795+
return
796+
794797
# may pass tuple instead of argument list
795798
if len(args) == 1 and isinstance(args[0], tuple):
796799
args = args[0]

0 commit comments

Comments
 (0)