sw_engine: fixing oveflow

An overflow occurred for big shapes with a dashed stroke,
since a contour end points were stored as the uint16 type
(instead of the uint32 type).
This commit is contained in:
mgrudzinska 2022-03-22 23:50:24 +01:00 committed by Hermet Park
parent 1e8b8cbb53
commit 0925aa84a5
4 changed files with 7 additions and 7 deletions

View file

@ -99,9 +99,9 @@ struct SwSize
struct SwOutline struct SwOutline
{ {
SwPoint* pts; //the outline's points SwPoint* pts; //the outline's points
uint16_t ptsCnt; //number of points in the glyph uint32_t ptsCnt; //number of points in the glyph
uint16_t reservedPtsCnt; uint32_t reservedPtsCnt;
uint16_t* cntrs; //the contour end points uint32_t* cntrs; //the contour end points
uint16_t cntrsCnt; //number of contours in glyph uint16_t cntrsCnt; //number of contours in glyph
uint16_t reservedCntrsCnt; uint16_t reservedCntrsCnt;
uint8_t* types; //curve type uint8_t* types; //curve type

View file

@ -46,7 +46,7 @@ static bool _genOutline(SwImage* image, const Matrix* transform, SwMpool* mpool,
if (outline->reservedCntrsCnt < 1) { if (outline->reservedCntrsCnt < 1) {
outline->reservedCntrsCnt = 1; outline->reservedCntrsCnt = 1;
outline->cntrs = static_cast<uint16_t*>(realloc(outline->cntrs, outline->reservedCntrsCnt * sizeof(uint16_t))); outline->cntrs = static_cast<uint32_t*>(realloc(outline->cntrs, outline->reservedCntrsCnt * sizeof(uint32_t)));
outline->closed = static_cast<bool*>(realloc(outline->closed, outline->reservedCntrsCnt * sizeof(bool))); outline->closed = static_cast<bool*>(realloc(outline->closed, outline->reservedCntrsCnt * sizeof(bool)));
outline->closed[0] = true; outline->closed[0] = true;
} }

View file

@ -64,7 +64,7 @@ static bool _growOutlineContour(SwOutline& outline, uint32_t n)
{ {
if (outline.reservedCntrsCnt >= outline.cntrsCnt + n) return false; if (outline.reservedCntrsCnt >= outline.cntrsCnt + n) return false;
outline.reservedCntrsCnt = outline.cntrsCnt + n; outline.reservedCntrsCnt = outline.cntrsCnt + n;
outline.cntrs = static_cast<uint16_t*>(realloc(outline.cntrs, outline.reservedCntrsCnt * sizeof(uint16_t))); outline.cntrs = static_cast<uint32_t*>(realloc(outline.cntrs, outline.reservedCntrsCnt * sizeof(uint32_t)));
return true; return true;
} }

View file

@ -780,7 +780,7 @@ static void _exportBorderOutline(const SwStroke& stroke, SwOutline* outline, uin
auto src = border->tags; auto src = border->tags;
auto tags = outline->types + outline->ptsCnt; auto tags = outline->types + outline->ptsCnt;
auto cntrs = outline->cntrs + outline->cntrsCnt; auto cntrs = outline->cntrs + outline->cntrsCnt;
uint16_t idx = outline->ptsCnt; auto idx = outline->ptsCnt;
while (cnt > 0) { while (cnt > 0) {
@ -921,7 +921,7 @@ SwOutline* strokeExportOutline(SwStroke* stroke, SwMpool* mpool, unsigned tid)
outline->reservedPtsCnt = ptsCnt; outline->reservedPtsCnt = ptsCnt;
} }
if (outline->reservedCntrsCnt < cntrsCnt) { if (outline->reservedCntrsCnt < cntrsCnt) {
outline->cntrs = static_cast<uint16_t*>(realloc(outline->cntrs, sizeof(uint16_t) * cntrsCnt)); outline->cntrs = static_cast<uint32_t*>(realloc(outline->cntrs, sizeof(uint32_t) * cntrsCnt));
outline->reservedCntrsCnt = cntrsCnt; outline->reservedCntrsCnt = cntrsCnt;
} }