From: Vsevolod Stakhov Date: Mon, 16 Feb 2026 15:36:19 +0000 (+0000) Subject: [Fix] Catch all exceptions when loading fasttext model to avoid crash X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec830799e941fead586534cd17355802c97e7f9e;p=thirdparty%2Frspamd.git [Fix] Catch all exceptions when loading fasttext model to avoid crash When the fasttext language detection model file doesn't exist or is corrupted, fasttext library throws an exception. Add a catch-all handler to prevent crashes when the model path is invalid or the file is missing. Also improved error messages to include the model path for debugging. --- diff --git a/src/libmime/lang_detection_fasttext.cxx b/src/libmime/lang_detection_fasttext.cxx index 75b17d8b32..6688aac8ad 100644 --- a/src/libmime/lang_detection_fasttext.cxx +++ b/src/libmime/lang_detection_fasttext.cxx @@ -23,9 +23,9 @@ #include "contrib/fmt/include/fmt/base.h" #include "stat_api.h" #include "libserver/word.h" -#include #include #include +#include #endif #ifdef WITH_FASTTEXT @@ -53,13 +53,24 @@ public: const auto *model = ucl_object_find_key(opts_section, "fasttext_model"); if (model) { + const char *model_path = ucl_object_tostring(model); + + if (access(model_path, R_OK) != 0) { + msg_err_config("fasttext model '%s' is not readable: %s", + model_path, strerror(errno)); + loaded = false; + return; + } + try { - ft.loadModel(ucl_object_tostring(model)); + ft.loadModel(model_path); loaded = true; - model_fname = std::string{ucl_object_tostring(model)}; - } catch (std::exception &e) { - auto err_message = fmt::format("cannot load fasttext model: {}", e.what()); - msg_err_config("%s", err_message.c_str()); + model_fname = std::string{model_path}; + } catch (const std::exception &e) { + msg_err_config("cannot load fasttext model '%s': %s", model_path, e.what()); + loaded = false; + } catch (...) { + msg_err_config("cannot load fasttext model '%s': unknown error", model_path); loaded = false; } }