[PATCH] [cairo-matrix] Check for non-finite numbers in the matrices.
Chris Wilson
chris at chris-wilson.co.uk
Wed Jul 4 12:18:01 PDT 2007
Add a C99 isfinite() check on the matrix determinant which should catch
all attempts to corrupt our matrices.
---
configure.in | 8 ++++++++
src/cairo-matrix.c | 9 +++++++++
2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/configure.in b/configure.in
index e8a6191..0859b94 100644
--- a/configure.in
+++ b/configure.in
@@ -701,6 +701,9 @@ AC_MSG_RESULT([$warn_unused_result])
CAIRO_CC_TRY_FLAG([-fno-strict-aliasing],
[CAIRO_CFLAGS="$CAIRO_CFLAGS -fno-strict-aliasing"
PIXMAN_CFLAGS="$PIXMAN_CFLAGS -fno-strict-aliasing"])
+CAIRO_CC_TRY_FLAG([-std=gnu99],
+ [CFLAGS="-std=gnu99 $CFLAGS"
+ CAIRO_CFLAGS="-std=gnu99 $CAIRO_CFLAGS"])
AC_SUBST(CAIRO_REQUIRES)
AC_SUBST(CAIRO_NONPKGCONFIG_CFLAGS)
@@ -712,6 +715,11 @@ AC_SUBST(PIXMAN_CFLAGS)
AC_SUBST(PIXMAN_LDADD)
AC_SUBST(CAIROPERF_LIBS)
+# isfinite() depends on a C99 compiler
+AC_TRY_LINK([#include <math.h>],
+ [isfinite(1.0)],
+ AC_DEFINE(HAVE_ISFINITE, 1, [Define to 1 if you have isfinite() ]))
+
dnl ===========================================================================
dnl Check for gtk-doc and docbook
diff --git a/src/cairo-matrix.c b/src/cairo-matrix.c
index a504ea6..8e0daa2 100644
--- a/src/cairo-matrix.c
+++ b/src/cairo-matrix.c
@@ -474,6 +474,10 @@ cairo_matrix_invert (cairo_matrix_t *matrix)
if (det == 0)
return CAIRO_STATUS_INVALID_MATRIX;
+#ifdef HAVE_ISFINITE
+ if (! isfinite (det))
+ return CAIRO_STATUS_INVALID_MATRIX;
+#endif
_cairo_matrix_compute_adjoint (matrix);
_cairo_matrix_scalar_multiply (matrix, 1 / det);
--9jxsPFA5p3P2qPhR--
More information about the cairo
mailing list