[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 <noreply@anthropic.com>
This commit is contained in:
Behdad EsfahbodandClaude Opus 5.5 committed 2026-10-19 15:40:59 -06:00
1 parent 5e821de825
commit a71aa86c2b
3 files changed
+16 -4

No files matched your search

+5 -3
View File
@@ -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. */
+8 -1
View File
@@ -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,
+3
View File
@@ -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;
}