From c7064c18b9fecfb02c605e32448a81d8d8dbe173 Mon Sep 17 00:00:00 2001 From: deepend-tildeclub Date: Wed, 20 May 2026 14:51:06 -0600 Subject: [PATCH] Clamp spell-provider length casts on Win32 --- src/libenchant_win8/win8_provider.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/libenchant_win8/win8_provider.cpp b/src/libenchant_win8/win8_provider.cpp index 1a95edc4..9d017a9c 100644 --- a/src/libenchant_win8/win8_provider.cpp +++ b/src/libenchant_win8/win8_provider.cpp @@ -26,12 +26,19 @@ #include #include +#include #include "typedef.h" // for ssize_t #include ENCHANT_PLUGIN_DECLARE ("win8") +static int +size_to_int (size_t value) +{ + return value > static_cast(INT_MAX) ? INT_MAX : static_cast(value); +} + static char * utf16_to_utf8 (const wchar_t * const str, bool from_bcp47) { @@ -136,7 +143,7 @@ static void win8_dict_add_to_personal (EnchantDict *dict, const char *const word, size_t len) { auto checker = static_cast(dict->user_data); - wchar_t *wword = utf8_to_utf16 (word, static_cast(len), false); + wchar_t *wword = utf8_to_utf16 (word, size_to_int (len), false); checker->Add (wword); std::free (wword); @@ -146,7 +153,7 @@ static void win8_dict_add_to_session (EnchantDict *dict, const char *const word, size_t len) { auto checker = static_cast(dict->user_data); - wchar_t *wword = utf8_to_utf16 (word, static_cast(len), false); + wchar_t *wword = utf8_to_utf16 (word, size_to_int (len), false); checker->Ignore (wword); std::free (wword); @@ -156,7 +163,7 @@ static int win8_dict_check (EnchantDict *dict, const char *const word, size_t len) { auto checker = static_cast(dict->user_data); - wchar_t *wword = utf8_to_utf16 (word, static_cast(len), false); + wchar_t *wword = utf8_to_utf16 (word, size_to_int (len), false); IEnumSpellingError *errors; ISpellingError *error = nullptr; HRESULT hr; @@ -184,7 +191,7 @@ static char ** win8_dict_suggest (EnchantDict *dict, const char *const word, size_t len, size_t *out_n_suggs) { auto checker = static_cast(dict->user_data); - wchar_t *wword = utf8_to_utf16 (word, static_cast(len), false); + wchar_t *wword = utf8_to_utf16 (word, size_to_int (len), false); IEnumString *suggestions; HRESULT hr;