sw_engine shape: prevent crash when wrong pair of commands & points.
authorHermet Park <chuneon.park@samsung.com>
Tue, 24 Aug 2021 06:04:06 +0000 (15:04 +0900)
committerJunsuChoi <jsuya.choi@samsung.com>
Mon, 30 Aug 2021 00:44:59 +0000 (09:44 +0900)
add an exception handling,
if the given points count is not matched with expected points count from commands.

@Issue: https://github.com/Samsung/thorvg/issues/735

src/lib/sw_engine/tvgSwShape.cpp

index 4ccbff6..ecdaae1 100644 (file)
@@ -389,11 +389,13 @@ static bool _genOutline(SwShape* shape, const Shape* sdata, const Matrix* transf
     //smart reservation
     auto outlinePtsCnt = 0;
     auto outlineCntrsCnt = 0;
+    auto closeCnt = 0;
 
     for (uint32_t i = 0; i < cmdCnt; ++i) {
         switch(*(cmds + i)) {
             case PathCommand::Close: {
                 ++outlinePtsCnt;
+                ++closeCnt;
                 break;
             }
             case PathCommand::MoveTo: {
@@ -412,6 +414,11 @@ static bool _genOutline(SwShape* shape, const Shape* sdata, const Matrix* transf
         }
     }
 
+    if (static_cast<uint32_t>(outlinePtsCnt - closeCnt) > ptsCnt) {
+        TVGERR("SW_ENGINE", "Wrong a pair of the commands & points - required(%d), current(%d)", outlinePtsCnt - closeCnt, ptsCnt);
+        return false;
+    }
+
     ++outlinePtsCnt;    //for close
     ++outlineCntrsCnt;  //for end