From 58134bcfe75e4e0f42a00e44812f22b87754d8ff Mon Sep 17 00:00:00 2001 From: zach Date: Wed, 31 Aug 2022 08:05:42 -0700 Subject: [PATCH] fix: avoid segfault when using memcpy --- php/src/Extism.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/php/src/Extism.php b/php/src/Extism.php index e2715ed..a002aa2 100644 --- a/php/src/Extism.php +++ b/php/src/Extism.php @@ -74,14 +74,15 @@ class Plugin $data = json_encode($data); } - $str = FFI::new("const uint8_t *"); $length = strlen($data); + $ty = FFI::arrayType(FFI::type("uint8_t"), [$length]); + $str = FFI::new($ty); FFI::memcpy($str, $data, $length); global $lib; $id = $lib->extism_plugin_register($str, $length, $wasi); if ($id < 0) { - throw("Extism: unable to load plugin"); + throw new Exception("Extism: unable to load plugin"); } $this->id = $id;