[PATCH] [scaled-font] Guard against invalid matrices when creating the scaled font.

Chris Wilson chris at chris-wilson.co.uk
Mon Jan 26 12:52:29 PST 2009


Check the user input for validity before passing the values on to the
backend. Currently the error is detected by the backend and the error is
propagated onto the font-face.
---
 src/cairo-scaled-font.c |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index 57cfaa6..912dac5 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -38,9 +38,17 @@
  *      Chris Wilson <chris at chris-wilson.co.uk>
  */
 
+#define _GNU_SOURCE
+
 #include "cairoint.h"
 #include "cairo-scaled-font-private.h"
 
+#if _XOPEN_SOURCE >= 600 || defined (_ISOC99_SOURCE)
+#define ISFINITE(x) isfinite (x)
+#else
+#define ISFINITE(x) ((x) * (x) >= 0.) /* check for NaNs */
+#endif
+
 #define CAIRO_SCALED_GLYPH_PAGE_SHIFT 7
 #define CAIRO_SCALED_GLYPH_PAGE_SIZE (1 << CAIRO_SCALED_GLYPH_PAGE_SHIFT)
 #define CAIRO_SCALED_GLYPH_PAGE_INDEX(I) \
@@ -909,9 +917,19 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
     cairo_status_t status;
     cairo_scaled_font_map_t *font_map;
     cairo_scaled_font_t key, *old = NULL, *scaled_font = NULL;
+    double det;
+
+    status = font_face->status;
+    if (unlikely (status))
+	return _cairo_scaled_font_create_in_error (status);
+
+    det = _cairo_matrix_compute_determinant (font_matrix);
+    if (! ISFINITE (det))
+	return _cairo_scaled_font_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_MATRIX));
 
-    if (font_face->status)
-	return _cairo_scaled_font_create_in_error (font_face->status);
+    det = _cairo_matrix_compute_determinant (ctm);
+    if (! ISFINITE (det))
+	return _cairo_scaled_font_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_MATRIX));
 
     status = cairo_font_options_status ((cairo_font_options_t *) options);
     if (unlikely (status))
-- 
1.6.0.4


--=-eOh/xoSIvGBTom+9YKG9
Content-Disposition: attachment; filename*0=0025--scaled-font-Differentiate-fatal-error-when-creatin.patc; filename*1=h
Content-Type: text/x-patch; name="0025--scaled-font-Differentiate-fatal-error-when-creatin.patch"; charset="UTF-8"
Content-Transfer-Encoding: 7bit



More information about the cairo mailing list