Commit 438ecc34 for libheif
commit 438ecc34cfee08b6f26fae74afb59b7c21acc191
Author: Dirk Farin <dirk.farin@gmail.com>
Date: Wed Jun 17 22:03:51 2026 +0200
if the plugin directory is set to the empty string, do not try to scan this
diff --git a/libheif/plugins_unix.cc b/libheif/plugins_unix.cc
index e7ca9e66..b674dc3d 100644
--- a/libheif/plugins_unix.cc
+++ b/libheif/plugins_unix.cc
@@ -57,6 +57,14 @@ std::vector<std::string> list_all_potential_plugins_in_directory_unix(const char
{
std::vector<std::string> result;
+ // An empty directory string means there is no plugin directory to scan. This happens
+ // when the library is built with an empty PLUGIN_DIRECTORY and no LIBHEIF_PLUGIN_PATH
+ // is set. opendir("") fails anyway, but skip it explicitly to mirror the Windows path
+ // and avoid building bogus "/plugin.so" filenames.
+ if (directory == nullptr || directory[0] == '\0') {
+ return result;
+ }
+
DIR* dir = opendir(directory);
if (dir == nullptr) {
return {}; // TODO: return error_cannot_read_plugin_directory;
diff --git a/libheif/plugins_windows.cc b/libheif/plugins_windows.cc
index b11cec94..13428579 100644
--- a/libheif/plugins_windows.cc
+++ b/libheif/plugins_windows.cc
@@ -49,6 +49,14 @@ std::vector<std::string> list_all_potential_plugins_in_directory_windows(const c
{
std::vector<std::string> result;
+ // An empty directory string would build the search pattern "\\*.dll", which makes
+ // FindFirstFile() scan the root of the current drive (e.g. C:\). This happens when
+ // the library is built with an empty PLUGIN_DIRECTORY and no LIBHEIF_PLUGIN_PATH is
+ // set. Skip scanning in that case so that heif_init() does not fail on stray DLLs.
+ if (directory == nullptr || directory[0] == '\0') {
+ return result;
+ }
+
HANDLE hFind;
WIN32_FIND_DATA FindFileData;