From 17d9938ece6090c4e0e9871520cbd5ca7eaffc68 Mon Sep 17 00:00:00 2001 From: nulano Date: Fri, 27 Sep 2019 21:58:17 +0200 Subject: [PATCH] spider labrec ceil --- Tests/test_file_spider.py | 12 ++++++++++++ src/PIL/SpiderImagePlugin.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_spider.py b/Tests/test_file_spider.py index 8a1eb6637..340208486 100644 --- a/Tests/test_file_spider.py +++ b/Tests/test_file_spider.py @@ -1,4 +1,5 @@ import tempfile +from io import BytesIO from PIL import Image, ImageSequence, SpiderImagePlugin @@ -117,3 +118,14 @@ class TestImageSpider(PillowTestCase): for i, frame in enumerate(ImageSequence.Iterator(im)): if i > 1: self.fail("Non-stack DOS file test failed") + + # for issue #4093 + def test_odd_size(self): + data = BytesIO() + width = 100 + im = Image.new("F", (width, 64)) + im.save(data, format="SPIDER") + + data.seek(0) + im2 = Image.open(data) + self.assert_image_equal(im, im2) diff --git a/src/PIL/SpiderImagePlugin.py b/src/PIL/SpiderImagePlugin.py index 5663a5b53..f1cae4d9f 100644 --- a/src/PIL/SpiderImagePlugin.py +++ b/src/PIL/SpiderImagePlugin.py @@ -236,7 +236,7 @@ def loadImageSeries(filelist=None): def makeSpiderHeader(im): nsam, nrow = im.size lenbyt = nsam * 4 # There are labrec records in the header - labrec = 1024 / lenbyt + labrec = int(1024 / lenbyt) if 1024 % lenbyt != 0: labrec += 1 labbyt = labrec * lenbyt