From 17bbedc77c7f51ca1d635451fbde0b74b72096ce Mon Sep 17 00:00:00 2001 From: Jared Van Bortel Date: Tue, 4 Feb 2025 13:08:49 -0500 Subject: [PATCH] llmodel: do not crash on nonexistent dir in impl search path Signed-off-by: Jared Van Bortel --- gpt4all-backend/src/llmodel.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gpt4all-backend/src/llmodel.cpp b/gpt4all-backend/src/llmodel.cpp index ee247f35..de130593 100644 --- a/gpt4all-backend/src/llmodel.cpp +++ b/gpt4all-backend/src/llmodel.cpp @@ -140,9 +140,14 @@ const std::vector &LLModel::Implementation::implementat std::string path; // Split the paths string by the delimiter and process each path. while (std::getline(ss, path, ';')) { - std::u8string u8_path(path.begin(), path.end()); + fs::directory_iterator iter; + try { + iter = fs::directory_iterator(std::u8string(path.begin(), path.end())); + } catch (const fs::filesystem_error &) { + continue; // skip nonexistent path + } // Iterate over all libraries - for (const auto &f : fs::directory_iterator(u8_path)) { + for (const auto &f : iter) { const fs::path &p = f.path(); if (p.extension() != LIB_FILE_EXT) continue;