Merge pull request #6986 from fcarron/fix_libtiff_file_pointer

Close file pointer copy in the libtiff encoder if still open
This commit is contained in:
Andrew Murray 2023-03-05 16:24:19 +11:00 committed by GitHub
commit eda95342ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -1065,3 +1065,9 @@ class TestFileLibTiff(LibTiffTestCase):
out = str(tmp_path / "temp.tif") out = str(tmp_path / "temp.tif")
with pytest.raises(SystemError): with pytest.raises(SystemError):
im.save(out, compression=compression) im.save(out, compression=compression)
def test_save_many_compressed(self, tmp_path):
im = hopper()
out = str(tmp_path / "temp.tif")
for _ in range(10000):
im.save(out, compression="jpeg")

View File

@ -1850,6 +1850,11 @@ def _save(im, fp, filename):
fp.write(data) fp.write(data)
if errcode: if errcode:
break break
if _fp:
try:
os.close(_fp)
except OSError:
pass
if errcode < 0: if errcode < 0:
msg = f"encoder error {errcode} when writing image file" msg = f"encoder error {errcode} when writing image file"
raise OSError(msg) raise OSError(msg)