From 9a0954091d7108be84f5d9a624d8e7d0d7beced8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20B=C3=BCnzli?= Date: Thu, 13 Feb 2014 22:21:17 +0100 Subject: Bug 695040: prevent hang in path flattening If the expansion of a transformation matrix is huge, the path flatness becomes so small that even simple paths consist of millions of edges which easily causes MuPDF to hang quite long for simple documents. One solution for this is to limit the allowed flatness. --- source/fitz/draw-device.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/source/fitz/draw-device.c b/source/fitz/draw-device.c index 3effa3a7..98b7990c 100644 --- a/source/fitz/draw-device.c +++ b/source/fitz/draw-device.c @@ -256,6 +256,9 @@ fz_draw_fill_path(fz_device *devp, fz_path *path, int even_odd, const fz_matrix if (model == NULL) model = fz_device_gray(dev->ctx); + if (flatness < 0.001f) + flatness = 0.001f; + fz_reset_gel(dev->gel, &state->scissor); fz_flatten_fill_path(dev->gel, path, ctm, flatness); fz_sort_gel(dev->gel); @@ -308,6 +311,8 @@ fz_draw_stroke_path(fz_device *devp, fz_path *path, fz_stroke_state *stroke, con if (linewidth * expansion < 0.1f) linewidth = 1 / expansion; + if (flatness < 0.001f) + flatness = 0.001f; fz_reset_gel(dev->gel, &state->scissor); if (stroke->dash_len > 0) @@ -358,6 +363,9 @@ fz_draw_clip_path(fz_device *devp, fz_path *path, const fz_rect *rect, int even_ fz_colorspace *model; fz_context *ctx = dev->ctx; + if (flatness < 0.001f) + flatness = 0.001f; + fz_reset_gel(dev->gel, &state->scissor); fz_flatten_fill_path(dev->gel, path, ctm, flatness); fz_sort_gel(dev->gel); @@ -422,6 +430,8 @@ fz_draw_clip_stroke_path(fz_device *devp, fz_path *path, const fz_rect *rect, fz if (linewidth * expansion < 0.1f) linewidth = 1 / expansion; + if (flatness < 0.001f) + flatness = 0.001f; fz_reset_gel(dev->gel, &state->scissor); if (stroke->dash_len > 0) -- cgit v1.2.3