diff --git a/src/hb-wasm-api-face.hh b/src/hb-wasm-api-face.hh index 5f38710a8..ce767c030 100644 --- a/src/hb-wasm-api-face.hh +++ b/src/hb-wasm-api-face.hh @@ -31,22 +31,33 @@ namespace hb { namespace wasm { -HB_WASM_API_COMPOUND (blob_t, face_copy_table) (HB_WASM_EXEC_ENV_COMPOUND - ptr_d(face_t, face), - tag_t table_tag) +HB_WASM_API (bool_t, face_copy_table) (HB_WASM_EXEC_ENV + ptr_d(face_t, face), + tag_t table_tag, + ptr_d(blob_t, blob)) { - HB_RETURN_STRUCT (blob_t, ret); HB_REF2OBJ (face); + HB_PTR_PARAM (blob_t, blob); + if (unlikely (!blob)) + return false; - hb_blob_t *blob = hb_face_reference_table (face, table_tag); + hb_blob_t *hb_blob = hb_face_reference_table (face, table_tag); unsigned length; - const char *data = hb_blob_get_data (blob, &length); + const char *data = hb_blob_get_data (hb_blob, &length); - ret.length = length; - ret.data = wasm_runtime_module_dup_data (module_inst, data, length); + blob->length = length; + blob->data = wasm_runtime_module_dup_data (module_inst, data, length); - hb_blob_destroy (blob); + hb_blob_destroy (hb_blob); + + if (blob->length && !blob->data) + { + blob->length = 0; + return false; + } + + return true; } HB_WASM_API (unsigned, face_get_upem) (HB_WASM_EXEC_ENV diff --git a/src/hb-wasm-api-list.hh b/src/hb-wasm-api-list.hh index 65b982ef2..545b2f098 100644 --- a/src/hb-wasm-api-list.hh +++ b/src/hb-wasm-api-list.hh @@ -67,7 +67,7 @@ static NativeSymbol _hb_wasm_native_symbols[] = NATIVE_SYMBOL ("(i)", buffer_reverse_clusters), /* face */ - NATIVE_SYMBOL ("(iii)", face_copy_table), + NATIVE_SYMBOL ("(iii)i", face_copy_table), NATIVE_SYMBOL ("(i)i", face_get_upem), /* font */ diff --git a/src/hb-wasm-api.h b/src/hb-wasm-api.h index 8f0748938..43327cd35 100644 --- a/src/hb-wasm-api.h +++ b/src/hb-wasm-api.h @@ -173,9 +173,10 @@ HB_WASM_API (void, buffer_reverse_clusters) (HB_WASM_EXEC_ENV typedef struct face_t face_t; -HB_WASM_API_COMPOUND (blob_t, face_copy_table) (HB_WASM_EXEC_ENV_COMPOUND - ptr_d(face_t, face), - tag_t table_tag); +HB_WASM_API (bool_t, face_copy_table) (HB_WASM_EXEC_ENV + ptr_d(face_t, face), + tag_t table_tag, + ptr_d(blob_t, blob)); HB_WASM_API (unsigned, face_get_upem) (HB_WASM_EXEC_ENV ptr_d(face_t, face)); diff --git a/src/wasm/graphite/shape.cc b/src/wasm/graphite/shape.cc index 7a5ca71d9..94a896975 100644 --- a/src/wasm/graphite/shape.cc +++ b/src/wasm/graphite/shape.cc @@ -21,7 +21,9 @@ uint32_t heap_size = 2 * 1024 * 1024; static const void *copy_table (const void *data, unsigned int tag, size_t *len) { face_t *face = (face_t *) data; - blob_t blob = face_copy_table (face, tag); + blob_t blob; + if (!face_copy_table (face, tag, &blob)) + abort (); *len = blob.length; return blob.data; diff --git a/src/wasm/sample/c/shape-fallback.cc b/src/wasm/sample/c/shape-fallback.cc index ecfb6948a..85834a1c1 100644 --- a/src/wasm/sample/c/shape-fallback.cc +++ b/src/wasm/sample/c/shape-fallback.cc @@ -3,6 +3,7 @@ #include extern "C" { +void abort (); void debugprint (const char *s); void debugprint1 (const char *s, int32_t); void debugprint2 (const char *s, int32_t, int32_t); @@ -17,7 +18,9 @@ shape (void *shape_plan, { face_t *face = font_get_face (font); - blob_t blob = face_copy_table (face, TAG ('c','m','a','p')); + blob_t blob; + if (!face_copy_table (face, TAG ('c','m','a','p'), &blob)) + abort (); debugprint1 ("cmap length", blob.length);