Fix for #185
- prevent infinite loop when gradient ID is left to empty string - prevent infinite loop when gradient references to self - lookup up to 32 references back
This commit is contained in:
parent
e7f5981b1e
commit
ddd39e9669
@ -32,7 +32,7 @@ int main()
|
|||||||
NSVGrasterizer *rast = NULL;
|
NSVGrasterizer *rast = NULL;
|
||||||
unsigned char* img = NULL;
|
unsigned char* img = NULL;
|
||||||
int w, h;
|
int w, h;
|
||||||
const char* filename = "../example/23.svg";
|
const char* filename = "../example/_timeout_2.svg";
|
||||||
|
|
||||||
printf("parsing %s\n", filename);
|
printf("parsing %s\n", filename);
|
||||||
image = nsvgParseFromFile(filename, "px", 96.0f);
|
image = nsvgParseFromFile(filename, "px", 96.0f);
|
||||||
|
@ -805,7 +805,9 @@ static float nsvg__convertToPixels(NSVGparser* p, NSVGcoordinate c, float orig,
|
|||||||
static NSVGgradientData* nsvg__findGradientData(NSVGparser* p, const char* id)
|
static NSVGgradientData* nsvg__findGradientData(NSVGparser* p, const char* id)
|
||||||
{
|
{
|
||||||
NSVGgradientData* grad = p->gradients;
|
NSVGgradientData* grad = p->gradients;
|
||||||
while (grad) {
|
if (id == NULL || *id == '\0')
|
||||||
|
return NULL;
|
||||||
|
while (grad != NULL) {
|
||||||
if (strcmp(grad->id, id) == 0)
|
if (strcmp(grad->id, id) == 0)
|
||||||
return grad;
|
return grad;
|
||||||
grad = grad->next;
|
grad = grad->next;
|
||||||
@ -822,19 +824,26 @@ static NSVGgradient* nsvg__createGradient(NSVGparser* p, const char* id, const f
|
|||||||
NSVGgradient* grad;
|
NSVGgradient* grad;
|
||||||
float ox, oy, sw, sh, sl;
|
float ox, oy, sw, sh, sl;
|
||||||
int nstops = 0;
|
int nstops = 0;
|
||||||
|
int refIter;
|
||||||
|
|
||||||
data = nsvg__findGradientData(p, id);
|
data = nsvg__findGradientData(p, id);
|
||||||
if (data == NULL) return NULL;
|
if (data == NULL) return NULL;
|
||||||
|
|
||||||
// TODO: use ref to fill in all unset values too.
|
// TODO: use ref to fill in all unset values too.
|
||||||
ref = data;
|
ref = data;
|
||||||
|
refIter = 0;
|
||||||
while (ref != NULL) {
|
while (ref != NULL) {
|
||||||
|
NSVGgradientData* nextRef = NULL;
|
||||||
if (stops == NULL && ref->stops != NULL) {
|
if (stops == NULL && ref->stops != NULL) {
|
||||||
stops = ref->stops;
|
stops = ref->stops;
|
||||||
nstops = ref->nstops;
|
nstops = ref->nstops;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ref = nsvg__findGradientData(p, ref->ref);
|
nextRef = nsvg__findGradientData(p, ref->ref);
|
||||||
|
if (nextRef == ref) break; // prevent infite loops on malformed data
|
||||||
|
ref = nextRef;
|
||||||
|
refIter++;
|
||||||
|
if (refIter > 32) break; // prevent infite loops on malformed data
|
||||||
}
|
}
|
||||||
if (stops == NULL) return NULL;
|
if (stops == NULL) return NULL;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user