From a71aa86c2bac114fafb6b47f8da02024ecb44fa6 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 19 Oct 2026 15:33:05 -0600 Subject: [PATCH] [wasm] Don't pass unvalidated guest pointers to host functions buffer_set_contents, face_create, and font_set_coords converted guest array addresses to native pointers, using nullptr when validation failed, but then handed the result to hb_memcpy(), hb_blob_create(), and hb_font_set_var_coords_normalized() unconditionally. A font wasm module passing an out-of-range address with a nonzero length made the host copy from NULL. face_create also dereferenced the blob_t parameter without checking it. Fail the call when validation fails. buffer_set_contents now validates before resizing the buffer. Tested with the reporter's PoC fonts: each now traps in the guest with "out of bounds memory access" instead of faulting in the host. meson test passes on a -Dwasm=enabled build. Reported-by: Ostrolab security team Co-Authored-By: Claude Opus 5.5 --- src/hb-wasm-api-buffer.hh | 8 +++++--- src/hb-wasm-api-face.hh | 9 ++++++++- src/hb-wasm-api-font.hh | 3 +++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/hb-wasm-api-buffer.hh b/src/hb-wasm-api-buffer.hh index 64217a041..3cf793850 100644 --- a/src/hb-wasm-api-buffer.hh +++ b/src/hb-wasm-api-buffer.hh @@ -164,11 +164,13 @@ HB_WASM_API (bool_t, buffer_set_contents) (HB_WASM_EXEC_ENV if (unlikely (hb_unsigned_mul_overflows (length, sizeof (buffer->info[0]), &bytes))) return false; - if (unlikely (!buffer->resize (length))) - return false; - glyph_info_t *info = (glyph_info_t *) (validate_app_addr (contents->info, bytes) ? addr_app_to_native (contents->info) : nullptr); glyph_position_t *pos = (glyph_position_t *) (validate_app_addr (contents->pos, bytes) ? addr_app_to_native (contents->pos) : nullptr); + if (unlikely (!info || !pos)) + return false; + + if (unlikely (!buffer->resize (length))) + return false; if (!buffer->have_positions) buffer->clear_positions (); /* This is wasteful. */ diff --git a/src/hb-wasm-api-face.hh b/src/hb-wasm-api-face.hh index 22e50e944..e48a1d761 100644 --- a/src/hb-wasm-api-face.hh +++ b/src/hb-wasm-api-face.hh @@ -36,8 +36,15 @@ HB_WASM_API (ptr_t(face_t), face_create) (HB_WASM_EXEC_ENV unsigned int index) { HB_PTR_PARAM (blob_t, blob); + if (unlikely (!blob)) + return nullref; + + char *data = HB_ARRAY_APP2NATIVE (char, blob->data, blob->length); + if (unlikely (!data)) + return nullref; + hb_blob_t *hb_blob = hb_blob_create( - HB_ARRAY_APP2NATIVE (char, blob->data, blob->length), + data, blob->length, HB_MEMORY_MODE_DUPLICATE, NULL, diff --git a/src/hb-wasm-api-font.hh b/src/hb-wasm-api-font.hh index 8dbeda0bb..2767ea3da 100644 --- a/src/hb-wasm-api-font.hh +++ b/src/hb-wasm-api-font.hh @@ -256,6 +256,9 @@ HB_WASM_API (bool_t, font_set_coords) (HB_WASM_EXEC_ENV return false; const int *our_coords = (const int *) (validate_app_addr (coords->coords, bytes) ? addr_app_to_native (coords->coords) : nullptr); + if (unlikely (!our_coords)) + return false; + hb_font_set_var_coords_normalized(font, our_coords, length); return true; }