From c667677014c91041ea57f55ce583d3e005bfcf09 Mon Sep 17 00:00:00 2001 From: zhaoyixin1998 Date: Tue, 7 Jul 2026 16:33:33 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=87=8F=E6=B3=95?= =?UTF-8?q?=E4=B8=8B=E6=BA=A2=E4=BF=9D=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhaoyixin1998 --- .../kits/napi/src/napi_accessibility_utils.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/napi/src/napi_accessibility_utils.cpp b/interfaces/kits/napi/src/napi_accessibility_utils.cpp index 0c474c329..02216d73f 100644 --- a/interfaces/kits/napi/src/napi_accessibility_utils.cpp +++ b/interfaces/kits/napi/src/napi_accessibility_utils.cpp @@ -462,6 +462,17 @@ bool CheckObserverEqual(napi_env env, napi_value observer, napi_env iterEnv, nap return false; } +static int32_t safe_subtract(int32_t minuend, int32_t subtrahend) +{ + if (subtrahend > 0 && minuend < INT32_MIN + subtrahend) { + return 0; + } + if (subtrahend < 0 && minuend > INT32_MAX + subtrahend) { + return 0; + } + return minuend - subtrahend; +} + /********************************************************** * Convert native object to js object *********************************************************/ @@ -476,12 +487,12 @@ void ConvertRectToJS(napi_env env, napi_value result, const Accessibility::Rect& NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "top", nLeftTopY)); napi_value nWidth = nullptr; - int32_t width = rect.GetRightBottomXScreenPostion() - rect.GetLeftTopXScreenPostion(); + int32_t width = safe_subtract(rect.GetRightBottomXScreenPostion(), rect.GetLeftTopXScreenPostion()); NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, width, &nWidth)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "width", nWidth)); napi_value nHeight = nullptr; - int32_t height = rect.GetRightBottomYScreenPostion() - rect.GetLeftTopYScreenPostion(); + int32_t height = safe_subtract(rect.GetRightBottomYScreenPostion(), rect.GetLeftTopYScreenPostion()); NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, height, &nHeight)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "height", nHeight)); } From 117c10879f70d377786b1477a4aa472af59bae99 Mon Sep 17 00:00:00 2001 From: zhaoyixin1998 Date: Tue, 7 Jul 2026 16:59:27 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=87=8F=E6=B3=95=E4=B8=8B=E6=BA=A2?= =?UTF-8?q?=E4=BF=9D=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhaoyixin1998 --- interfaces/kits/napi/src/napi_accessibility_utils.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/napi/src/napi_accessibility_utils.cpp b/interfaces/kits/napi/src/napi_accessibility_utils.cpp index 02216d73f..b3e071c0d 100644 --- a/interfaces/kits/napi/src/napi_accessibility_utils.cpp +++ b/interfaces/kits/napi/src/napi_accessibility_utils.cpp @@ -462,7 +462,7 @@ bool CheckObserverEqual(napi_env env, napi_value observer, napi_env iterEnv, nap return false; } -static int32_t safe_subtract(int32_t minuend, int32_t subtrahend) +static int32_t SafeSubtract(int32_t minuend, int32_t subtrahend) { if (subtrahend > 0 && minuend < INT32_MIN + subtrahend) { return 0; @@ -487,12 +487,12 @@ void ConvertRectToJS(napi_env env, napi_value result, const Accessibility::Rect& NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "top", nLeftTopY)); napi_value nWidth = nullptr; - int32_t width = safe_subtract(rect.GetRightBottomXScreenPostion(), rect.GetLeftTopXScreenPostion()); + int32_t width = SafeSubtract(rect.GetRightBottomXScreenPostion(), rect.GetLeftTopXScreenPostion()); NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, width, &nWidth)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "width", nWidth)); napi_value nHeight = nullptr; - int32_t height = safe_subtract(rect.GetRightBottomYScreenPostion(), rect.GetLeftTopYScreenPostion()); + int32_t height = SafeSubtract(rect.GetRightBottomYScreenPostion(), rect.GetLeftTopYScreenPostion()); NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, height, &nHeight)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "height", nHeight)); }