[cairo] [PATCH] Improve error checking in TrueType subsetting

Adrian Johnson ajohnson at redneon.com
Sun Aug 27 05:28:02 PDT 2006


TrueType subsetting will SEGV when using OpenType fonts with CFF outlines.
-------------- next part --------------
diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c
index f1b0011..c5e1799 100644
--- a/src/cairo-truetype-subset.c
+++ b/src/cairo-truetype-subset.c
@@ -400,8 +400,11 @@ cairo_truetype_font_write_generic_table 
     unsigned long size;
 
     size = 0;
-    font->backend->load_truetype_table( font->scaled_font_subset->scaled_font,
-                                        tag, 0, NULL, &size);
+    if (font->backend->load_truetype_table( font->scaled_font_subset->scaled_font,
+					    tag, 0, NULL, &size) != CAIRO_STATUS_SUCCESS) {
+        font->status = CAIRO_INT_STATUS_UNSUPPORTED;
+        return font->status;
+    }
     status = cairo_truetype_font_allocate_write_buffer (font, size, &buffer);
     /* XXX: Need to check status here. */
     font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
@@ -473,8 +476,11 @@ cairo_truetype_font_write_glyf_table (ca
 	font->status = CAIRO_STATUS_NO_MEMORY;
 	return font->status;
     }
-    font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
-                                        TT_TAG_loca, 0, u.bytes, &size);
+    if (font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
+                                            TT_TAG_loca, 0, u.bytes, &size) != CAIRO_STATUS_SUCCESS) {
+        font->status = CAIRO_INT_STATUS_UNSUPPORTED;
+        return font->status;
+    }
 
     start_offset = _cairo_array_num_elements (&font->output);
     for (i = 0; i < font->base.num_glyphs; i++) {
@@ -566,17 +572,23 @@ cairo_truetype_font_write_hmtx_table (ca
         status = cairo_truetype_font_allocate_write_buffer (font, long_entry_size,
 							  (unsigned char **) &p);
         if (font->glyphs[i].parent_index < num_hmetrics) {
-            font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
-                                                TT_TAG_hmtx,
-                                                font->glyphs[i].parent_index * long_entry_size,
-                                                (unsigned char *) p, &long_entry_size);
+            if (font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
+                                                    TT_TAG_hmtx,
+                                                    font->glyphs[i].parent_index * long_entry_size,
+                                                    (unsigned char *) p, &long_entry_size) != CAIRO_STATUS_SUCCESS) {
+                font->status = CAIRO_INT_STATUS_UNSUPPORTED;
+                return font->status;
+            }
         }
         else
         {
-            font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
-                                                TT_TAG_hmtx,
-                                                (num_hmetrics - 1) * long_entry_size,
-                                                (unsigned char *) p, &short_entry_size);
+            if (font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
+                                                    TT_TAG_hmtx,
+                                                    (num_hmetrics - 1) * long_entry_size,
+                                                    (unsigned char *) p, &short_entry_size) != CAIRO_STATUS_SUCCESS) {
+                font->status = CAIRO_INT_STATUS_UNSUPPORTED;
+                return font->status;
+            }
             font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
                                                 TT_TAG_hmtx,
                                                 (num_hmetrics - 1) * long_entry_size +


More information about the cairo mailing list