From 77f0f3c11a5b9e2d5bbf20a6e2840c19822bc134 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 24 Feb 2023 20:01:22 -0700 Subject: [PATCH] [wasm-api] Make buffer_copy_contents return zero length on mem fail --- src/hb-wasm-api-buffer.hh | 4 ++-- src/hb-wasm-shape.cc | 15 ++------------- src/wasm-graphite/shape.cc | 2 ++ 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/hb-wasm-api-buffer.hh b/src/hb-wasm-api-buffer.hh index 78d44b572..91b3a8720 100644 --- a/src/hb-wasm-api-buffer.hh +++ b/src/hb-wasm-api-buffer.hh @@ -109,8 +109,8 @@ HB_WASM_API_COMPOUND (buffer_contents_t, buffer_copy_contents) (HB_WASM_EXEC_ENV ret.info = wasm_runtime_module_dup_data (module_inst, (const char *) buffer->info, length * sizeof (buffer->info[0])); ret.pos = wasm_runtime_module_dup_data (module_inst, (const char *) buffer->pos, length * sizeof (buffer->pos[0])); - if (unlikely (buffer->successful && (!ret.info || !ret.pos))) - buffer->successful = false; + if (!ret.info || !ret.pos) + ret.length = 0; } HB_WASM_API (bool_t, buffer_set_contents) (HB_WASM_EXEC_ENV diff --git a/src/hb-wasm-shape.cc b/src/hb-wasm-shape.cc index b43a8c9fb..a44ef5e23 100644 --- a/src/hb-wasm-shape.cc +++ b/src/hb-wasm-shape.cc @@ -348,21 +348,10 @@ retry: wasm_runtime_module_free (module_inst, arguments[2].of.i32); - if (unlikely (buffer->in_error ())) - { - DEBUG_MSG (WASM, module_inst, "Buffer in error. Memory allocation fail in the wasm?"); - if (retried) - goto fail; - buffer->successful = true; - retried = true; - release_shape_plan (face_data, plan); - goto retry; - } - - if (unlikely (!ret)) + if (unlikely (!ret || !results[0].of.i32)) { DEBUG_MSG (WASM, module_inst, "Calling shape() failed: %s", - wasm_runtime_get_exception(module_inst)); + wasm_runtime_get_exception (module_inst)); if (retried) goto fail; buffer->successful = true; diff --git a/src/wasm-graphite/shape.cc b/src/wasm-graphite/shape.cc index 80ef1c500..d4abc735a 100644 --- a/src/wasm-graphite/shape.cc +++ b/src/wasm-graphite/shape.cc @@ -75,6 +75,8 @@ shape (void *shape_plan, } buffer_contents_t contents = buffer_copy_contents (buffer); + if (!contents.length) + return false; gr_segment *seg = nullptr; const gr_slot *is;