From d08d7ee99e4f5f986f37709ab7308dcbc8c4a1d8 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 25 Jan 2026 22:55:19 +1100 Subject: [PATCH] Check ext is not empty during save --- src/PIL/Image.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 3e37754e1..8a28b56bd 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -404,6 +404,9 @@ _EXTENSION_PLUGIN: dict[str, str] = { def _import_plugin_for_extension(ext: str | bytes) -> bool: """Import only the plugin needed for a specific file extension.""" + if not ext: + return False + if isinstance(ext, bytes): ext = ext.decode() ext = ext.lower() @@ -3633,7 +3636,7 @@ def open( # Try to import just the plugin needed for this file extension # before falling back to preinit() which imports common plugins ext = os.path.splitext(filename)[1] if filename else "" - if not (ext and _import_plugin_for_extension(ext)): + if not _import_plugin_for_extension(ext): preinit() warning_messages: list[str] = []