From d4aab64d075fbfbdc25f202eb61e7f0fa639286d Mon Sep 17 00:00:00 2001 From: Tony Coder <407243179@qq.com> Date: Mon, 31 Aug 2026 10:38:07 +0800 Subject: [PATCH] fix: reject invalid Maple range options Signed-off-by: Tony Coder <407243179@qq.com> --- .../codegen/maple/maple_be/src/cg/cg_option.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_option.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_option.cpp index 252edbfde4..c247566bf3 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_option.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_option.cpp @@ -14,6 +14,7 @@ */ #include "cg_option.h" +#include #include "cg_options.h" #include "triple.h" #include "option.h" @@ -286,8 +287,17 @@ void CGOptions::SetRange(const std::string &str, const std::string &cmd, Range & subRange.enable = true; if (comma != std::string::npos) { - subRange.begin = std::stoul(tmpStr.substr(0, comma), nullptr); - subRange.end = std::stoul(tmpStr.substr(comma + 1, std::string::npos - (comma + 1)), nullptr); + const std::string beginText = tmpStr.substr(0, comma); + const std::string endText = tmpStr.substr(comma + 1); + uint64 beginValue = 0; + uint64 endValue = 0; + auto beginParsed = std::from_chars(beginText.data(), beginText.data() + beginText.size(), beginValue); + auto endParsed = std::from_chars(endText.data(), endText.data() + endText.size(), endValue); + CHECK_FATAL(beginParsed.ec == std::errc{} && beginParsed.ptr == beginText.data() + beginText.size() && + endParsed.ec == std::errc{} && endParsed.ptr == endText.data() + endText.size(), + "invalid range values for %s", cmd.c_str()); + subRange.begin = beginValue; + subRange.end = endValue; } CHECK_FATAL(range.begin < range.end, "invalid values for %s=%lu,%lu", cmd.c_str(), subRange.begin, subRange.end); }