tvg_saver TvgBinInterpreter: prevent misaligned memory access

When parsing a binary stored as a char type,
interpreter can access the misaligned memory while accessing it with a pointer.
To prevent that, pass the array copied to memcpy as tvg Object.
This commit is contained in:
JunsuChoi 2021-11-22 16:09:54 +09:00 committed by Hermet Park
parent 80cc0177fb
commit baab43aff2

View file

@ -248,12 +248,20 @@ static bool _parseShapeStrokeDashPattern(const char *ptr, const char *end, Shape
uint32_t dashPatternCnt;
READ_UI32(&dashPatternCnt, ptr);
ptr += SIZE(uint32_t);
const float* dashPattern = (float*) ptr;
if (dashPatternCnt > 0) {
float* dashPattern = static_cast<float*>(malloc(sizeof(float) * dashPatternCnt));
if (!dashPattern) return false;
memcpy(dashPattern, ptr, sizeof(float) * dashPatternCnt);
ptr += SIZE(float) * dashPatternCnt;
if (ptr > end) return false;
if (ptr > end) {
free(dashPattern);
return false;
}
shape->stroke(dashPattern, dashPatternCnt);
free(dashPattern);
}
return true;
}