From 1784fd403e3dce357f018639730dd75e138904b5 Mon Sep 17 00:00:00 2001 From: Andrea Canciani Date: Thu, 9 Dec 2010 14:38:40 +0100 Subject: [PATCH] arc: Clamp to 65536 full circles To limit the amount of memory used for arcs describing a circle wrapped multiple times we ignore the circles after the 65536th (but preserve the same start and end angle mod 2pi). --- src/cairo-arc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cairo-arc.c b/src/cairo-arc.c index 1b2713f39..c997e5c3c 100644 --- a/src/cairo-arc.c +++ b/src/cairo-arc.c @@ -38,6 +38,8 @@ #include "cairo-arc-private.h" +#define MAX_FULL_CIRCLES 65536 + /* Spline deviation from the circle in radius would be given by: error = sqrt (x**2 + y**2) - 1 @@ -184,8 +186,13 @@ _cairo_arc_in_direction (cairo_t *cr, if (cairo_status (cr)) return; - while (angle_max - angle_min > 4 * M_PI) - angle_max -= 2 * M_PI; + assert (angle_max >= angle_min); + + if (angle_max - angle_min > 2 * M_PI * MAX_FULL_CIRCLES) { + angle_max = fmod (angle_max - angle_min, 2 * M_PI); + angle_min = fmod (angle_min, 2 * M_PI); + angle_max += angle_min + 2 * M_PI * MAX_FULL_CIRCLES; + } /* Recurse if drawing arc larger than pi */ if (angle_max - angle_min > M_PI) {