Fix accessing tables from NULL pointer
authorBehdad Esfahbod <behdad@behdad.org>
Mon, 10 May 2010 23:51:57 +0000 (19:51 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Mon, 10 May 2010 23:51:57 +0000 (19:51 -0400)
src/hb-font.cc
src/hb-open-type-private.hh
src/hb-ot-layout.cc

index b8b151b..20aeb16 100644 (file)
@@ -297,7 +297,7 @@ _hb_face_for_data_get_table (hb_tag_t tag, void *user_data)
 {
   hb_face_for_data_closure_t *data = (hb_face_for_data_closure_t *) user_data;
 
-  const OpenTypeFontFile &ot_file = *CastP<OpenTypeFontFile> (hb_blob_lock (data->blob));
+  const OpenTypeFontFile &ot_file = *Sanitizer<OpenTypeFontFile>::lock_instance (data->blob);
   const OpenTypeFontFace &ot_face = ot_file.get_face (data->index);
 
   const OpenTypeTable &table = ot_face.get_table_by_tag (tag);
index 023df83..8c3e8a4 100644 (file)
@@ -330,6 +330,11 @@ struct Sanitizer
       return hb_blob_create_empty ();
     }
   }
+
+  static const Type* lock_instance (hb_blob_t *blob) {
+    const char *base = hb_blob_lock (blob);
+    return unlikely (!base) ? &Null(Type) : CastP<Type> (base);
+  }
 };
 
 
index 04cc982..91f9fe9 100644 (file)
@@ -47,13 +47,13 @@ _hb_ot_layout_init (hb_face_t *face)
   memset (layout, 0, sizeof (*layout));
 
   layout->gdef_blob = Sanitizer<GDEF>::sanitize (hb_face_get_table (face, HB_OT_TAG_GDEF));
-  layout->gdef = CastP<GDEF> (hb_blob_lock (layout->gdef_blob));
+  layout->gdef = Sanitizer<GDEF>::lock_instance (layout->gdef_blob);
 
   layout->gsub_blob = Sanitizer<GSUB>::sanitize (hb_face_get_table (face, HB_OT_TAG_GSUB));
-  layout->gsub = CastP<GSUB> (hb_blob_lock (layout->gsub_blob));
+  layout->gsub = Sanitizer<GSUB>::lock_instance (layout->gsub_blob);
 
   layout->gpos_blob = Sanitizer<GPOS>::sanitize (hb_face_get_table (face, HB_OT_TAG_GPOS));
-  layout->gpos = CastP<GPOS> (hb_blob_lock (layout->gpos_blob));
+  layout->gpos = Sanitizer<GPOS>::lock_instance (layout->gpos_blob);
 }
 
 void