[wasm-api] Respect existing blob allocation in face_copy_blob

This commit is contained in:
Behdad Esfahbod 2023-02-25 09:30:40 -07:00
parent e7540043de
commit f2d227ad9f
4 changed files with 20 additions and 4 deletions

View File

@ -44,10 +44,25 @@ HB_WASM_API (bool_t, face_copy_table) (HB_WASM_EXEC_ENV
hb_blob_t *hb_blob = hb_face_reference_table (face, table_tag);
unsigned length;
const char *data = hb_blob_get_data (hb_blob, &length);
const char *hb_data = hb_blob_get_data (hb_blob, &length);
if (length <= blob->length)
{
char *data = (char *) (validate_app_addr (blob->data, blob->length) ? addr_app_to_native (blob->data) : nullptr);
if (unlikely (!data))
{
blob->length = 0;
return false;
}
memcpy (data, hb_data, length);
return true;
}
blob->length = length;
blob->data = wasm_runtime_module_dup_data (module_inst, data, length);
blob->data = wasm_runtime_module_dup_data (module_inst, hb_data, length);
hb_blob_destroy (hb_blob);

View File

@ -108,6 +108,7 @@ typedef struct
uint32_t length;
ptr_t(char) data;
} blob_t;
#define BLOB_INIT {0, 0}
HB_WASM_API (void, blob_free) (HB_WASM_EXEC_ENV
ptr_d(blob_t, blob));

View File

@ -21,7 +21,7 @@ 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;
blob_t blob = BLOB_INIT;
if (!face_copy_table (face, tag, &blob))
abort ();

View File

@ -18,7 +18,7 @@ shape (void *shape_plan,
{
face_t *face = font_get_face (font);
blob_t blob;
blob_t blob = BLOB_INIT;
if (!face_copy_table (face, TAG ('c','m','a','p'), &blob))
abort ();