sw_engine shape: prevent crash when wrong pair of commands & points.

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
This commit is contained in:
Hermet Park 2021-08-24 15:04:06 +09:00 committed by Hermet Park
parent 54b328b1a9
commit f2252787ee

View 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