mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-05-28 01:33:21 +03:00
Do not load image during save if file extension is unknown (#8835)
Co-authored-by: Andrew Murray <radarhere@users.noreply.github.com>
This commit is contained in:
parent
e1f0def839
commit
3c185d1f69
|
@ -43,7 +43,7 @@ def test_save() -> None:
|
|||
# Arrange
|
||||
with Image.open(TEST_FILE) as im:
|
||||
dummy_fp = BytesIO()
|
||||
dummy_filename = "dummy.filename"
|
||||
dummy_filename = "dummy.h5"
|
||||
|
||||
# Act / Assert: stub cannot save without an implemented handler
|
||||
with pytest.raises(OSError):
|
||||
|
|
|
@ -2510,13 +2510,6 @@ class Image:
|
|||
# only set the name for metadata purposes
|
||||
filename = os.fspath(fp.name)
|
||||
|
||||
# may mutate self!
|
||||
self._ensure_mutable()
|
||||
|
||||
save_all = params.pop("save_all", False)
|
||||
self.encoderinfo = {**getattr(self, "encoderinfo", {}), **params}
|
||||
self.encoderconfig: tuple[Any, ...] = ()
|
||||
|
||||
preinit()
|
||||
|
||||
filename_ext = os.path.splitext(filename)[1].lower()
|
||||
|
@ -2531,6 +2524,13 @@ class Image:
|
|||
msg = f"unknown file extension: {ext}"
|
||||
raise ValueError(msg) from e
|
||||
|
||||
# may mutate self!
|
||||
self._ensure_mutable()
|
||||
|
||||
save_all = params.pop("save_all", False)
|
||||
self.encoderinfo = {**getattr(self, "encoderinfo", {}), **params}
|
||||
self.encoderconfig: tuple[Any, ...] = ()
|
||||
|
||||
if format.upper() not in SAVE:
|
||||
init()
|
||||
if save_all:
|
||||
|
|
Loading…
Reference in New Issue
Block a user