From a8aec7875aaf6c8d8d4ed37ce74705988b73e9c1 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Mon, 30 Sep 2013 16:45:15 +0100 Subject: Bug 694526: Spot non-invertable matrices and bale before stroking The bug fix added in the previous commit fails to work in this case (hang-9527.pdf) because the matrix is not invertible and hence the clipping rectangle ends up infinite. Spot this case here and return early. --- source/fitz/geometry.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'source/fitz/geometry.c') diff --git a/source/fitz/geometry.c b/source/fitz/geometry.c index 81450246..c7c3d198 100644 --- a/source/fitz/geometry.c +++ b/source/fitz/geometry.c @@ -213,6 +213,25 @@ fz_invert_matrix(fz_matrix *dst, const fz_matrix *src) return dst; } +int +fz_try_invert_matrix(fz_matrix *dst, const fz_matrix *src) +{ + /* Be careful to cope with dst == src */ + float a = src->a; + float det = a * src->d - src->b * src->c; + if (det >= -FLT_EPSILON && det <= FLT_EPSILON) + return 1; + det = 1 / det; + dst->a = src->d * det; + dst->b = -src->b * det; + dst->c = -src->c * det; + dst->d = a * det; + a = -src->e * dst->a - src->f * dst->c; + dst->f = -src->e * dst->b - src->f * dst->d; + dst->e = a; + return 0; +} + int fz_is_rectilinear(const fz_matrix *m) { -- cgit v1.2.3