Skip to content

Commit

Permalink
Merge pull request #6986 from fcarron/fix_libtiff_file_pointer
Browse files Browse the repository at this point in the history
Close file pointer copy in the libtiff encoder if still open
  • Loading branch information
radarhere authored Mar 5, 2023
2 parents b4c2344 + bf27074 commit eda9534
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Tests/test_file_libtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -1065,3 +1065,9 @@ def test_save_zero(self, compression, tmp_path):
out = str(tmp_path / "temp.tif")
with pytest.raises(SystemError):
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")
5 changes: 5 additions & 0 deletions src/PIL/TiffImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,11 @@ def _save(im, fp, filename):
fp.write(data)
if errcode:
break
if _fp:
try:
os.close(_fp)
except OSError:
pass
if errcode < 0:
msg = f"encoder error {errcode} when writing image file"
raise OSError(msg)
Expand Down

0 comments on commit eda9534

Please sign in to comment.