From: Vincent Sanders Date: Wed, 31 Aug 2016 14:19:46 +0000 (+0100) Subject: prevent division by zero for gradient with no points and add test X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=988e0d0819c7e6b068b1c1741a50b547f8414cf7;p=libsvgtiny.git prevent division by zero for gradient with no points and add test --- diff --git a/src/svgtiny_gradient.c b/src/svgtiny_gradient.c index f5984ea..c36df32 100644 --- a/src/svgtiny_gradient.c +++ b/src/svgtiny_gradient.c @@ -410,8 +410,7 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n, /* r, r0, r1 are distance along gradient vector */ gradient_norm_squared = gradient_dx * gradient_dx + gradient_dy * gradient_dy; - pts = svgtiny_list_create( - sizeof (struct grad_point)); + pts = svgtiny_list_create(sizeof (struct grad_point)); if (!pts) return svgtiny_OUT_OF_MEMORY; for (j = 0; j != n; ) { @@ -540,6 +539,13 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n, svgtiny_list_size(pts), min_pt, min_r); #endif + /* There must be at least a single point for the gradient */ + if (svgtiny_list_size(pts) == 0) { + svgtiny_list_free(pts); + + return svgtiny_OK; + } + /* render triangles */ stop_count = state->linear_gradient_stop_count; assert(2 <= stop_count); diff --git a/test/data/bad_gradient_points.svg b/test/data/bad_gradient_points.svg new file mode 100644 index 0000000..fc73313 --- /dev/null +++ b/test/data/bad_gradient_points.svg @@ -0,0 +1,45 @@ + + + + + + > + + + + + + + + + + + + + + + 4 /> + + + + + + + + 4 /> + + + + + + 4 /> + + + + + +