diff --git a/include/LightGBM/utils/common.h b/include/LightGBM/utils/common.h index 9d27bdfaae97..a61f0d29cbd4 100644 --- a/include/LightGBM/utils/common.h +++ b/include/LightGBM/utils/common.h @@ -494,9 +494,14 @@ inline static std::vector StringToArrayFast(const std::string& str, int n) { return std::vector(); } auto p_str = str.c_str(); + auto p_end = p_str + str.size(); __StringToTHelperFast::value> helper; std::vector ret(n); for (int i = 0; i < n; ++i) { + p_str = Common::SkipSpaceAndTab(p_str); + if (p_str >= p_end) { + Log::Fatal("Malformed model file: not enough values in string for array of size %d", n); + } p_str = helper(p_str, &ret[i]); } return ret;