From f61efc6d847b4fee3e19bc9e0964cab4df3c2e74 Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Tue, 16 Apr 2024 20:35:31 +0900 Subject: [PATCH] loader/svg: Add check to the limits of result of StrToFloat The string passed to the svg parser is not guaranteed to always be a valid string. Certain strings may have numbers that cannot be converted. Therefore, make sure to check whether the converted value is in the appropriate range before returning. related issue: https://github.com/thorvg/thorvg/issues/2078#issuecomment-2037495121 --- src/common/tvgStr.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/common/tvgStr.cpp b/src/common/tvgStr.cpp index 311b9865..1336f244 100644 --- a/src/common/tvgStr.cpp +++ b/src/common/tvgStr.cpp @@ -21,6 +21,7 @@ */ #include "config.h" +#include #include #include #include "tvgMath.h" @@ -197,6 +198,8 @@ float strToFloat(const char *nPtr, char **endPtr) success: if (endPtr) *endPtr = (char *)(a); + if (!std::isfinite(val)) return 0.0f; + return minus * val; error: