From 6ffa543165561ccfd6496ab400fa04480c65a47f Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Fri, 23 Oct 2020 01:32:52 +0200 Subject: [PATCH] common shape: handling dash patterns < 1 For the dash pattern values (both, length and gap) < 1 the program crashed. curLen - variable type changed from int to float. Change-Id: I9a50f1d247c210de7e5017b652554d94f00eb875 --- src/lib/sw_engine/tvgSwCommon.h | 2 +- src/lib/sw_engine/tvgSwShape.cpp | 3 +-- src/lib/tvgShape.cpp | 4 ++++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib/sw_engine/tvgSwCommon.h b/src/lib/sw_engine/tvgSwCommon.h index 8e5a1cb..ce54180 100644 --- a/src/lib/sw_engine/tvgSwCommon.h +++ b/src/lib/sw_engine/tvgSwCommon.h @@ -165,7 +165,7 @@ struct SwStroke struct SwDashStroke { SwOutline* outline; - int32_t curLen; + float curLen; int32_t curIdx; Point ptStart; Point ptCur; diff --git a/src/lib/sw_engine/tvgSwShape.cpp b/src/lib/sw_engine/tvgSwShape.cpp index d4cf9c2..cb2d90e 100644 --- a/src/lib/sw_engine/tvgSwShape.cpp +++ b/src/lib/sw_engine/tvgSwShape.cpp @@ -113,7 +113,6 @@ static void _outlineMoveTo(SwOutline& outline, const Point* to, const Matrix* tr _growOutlinePoint(outline, 1); outline.pts[outline.ptsCnt] = _transform(to, transform); - outline.types[outline.ptsCnt] = SW_CURVE_TYPE_POINT; if (outline.ptsCnt > 0) { @@ -285,7 +284,7 @@ static void _dashCubicTo(SwDashStroke& dash, const Point* ctrl1, const Point* ct _growOutlinePoint(*dash.outline, dash.outline->ptsCnt >> 1); _growOutlineContour(*dash.outline, dash.outline->cntrsCnt >> 1); - Bezier cur = { dash.ptCur, *ctrl1, *ctrl2, *to}; + Bezier cur = {dash.ptCur, *ctrl1, *ctrl2, *to}; auto len = bezLength(cur); if (len < dash.curLen) { diff --git a/src/lib/tvgShape.cpp b/src/lib/tvgShape.cpp index 7cd6476..2bf6c53 100644 --- a/src/lib/tvgShape.cpp +++ b/src/lib/tvgShape.cpp @@ -339,6 +339,9 @@ Result Shape::stroke(const float* dashPattern, uint32_t cnt) noexcept { if (cnt < 2 || !dashPattern) return Result::InvalidArguments; + for (uint32_t i = 0; i < cnt; i++) + if (dashPattern[i] < FLT_EPSILON) return Result::InvalidArguments; + if (!pImpl->strokeDash(dashPattern, cnt)) return Result::FailedAllocation; return Result::Success; @@ -350,6 +353,7 @@ uint32_t Shape::strokeDash(const float** dashPattern) const noexcept if (!pImpl->stroke) return 0; if (dashPattern) *dashPattern = pImpl->stroke->dashPattern; + return pImpl->stroke->dashCnt; } -- 2.7.4