This commit is contained in:
Marcus Brinkmann 2016-12-03 13:39:28 +00:00 committed by GitHub
commit af15102bbe
2 changed files with 16 additions and 6 deletions

View File

@ -1092,10 +1092,6 @@ class TiffImageFile(ImageFile.ImageFile):
self.tile = []
self.readonly = 0
# libtiff closed the fp in a, we need to close self.fp, if possible
if hasattr(self.fp, 'close'):
if not self.__next:
self.fp.close()
self.fp = None # might be shared
if err < 0:

View File

@ -370,7 +370,8 @@ class TestFileLibTiff(LibTiffTestCase):
fn = im.fp.fileno()
os.fstat(fn)
im.load() # this should close it.
im.load()
im.close() # this should close it.
self.assertRaises(OSError, lambda: os.fstat(fn))
im = None # this should force even more closed.
self.assertRaises(OSError, lambda: os.fstat(fn))
@ -399,6 +400,19 @@ class TestFileLibTiff(LibTiffTestCase):
TiffImagePlugin.READ_LIBTIFF = False
def test_multipage_nframes(self):
# issue #862
TiffImagePlugin.READ_LIBTIFF = True
im = Image.open('Tests/images/multipage.tiff')
frames = im.n_frames
self.assertEqual(frames, 3)
for idx in range(frames):
im.seek(0)
# Should not raise ValueError: I/O operation on closed file
im.load()
TiffImagePlugin.READ_LIBTIFF = False
def test__next(self):
TiffImagePlugin.READ_LIBTIFF = True
im = Image.open('Tests/images/hopper.tif')
@ -521,7 +535,7 @@ class TestFileLibTiff(LibTiffTestCase):
except:
self.fail("Should not get permission error here")
if __name__ == '__main__':