From 4a8d4c5a2966fbb05f2b4cd92b78cf805ddedcc7 Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Mon, 8 Apr 2024 20:06:20 +0300 Subject: [PATCH] fix(vm/compiler/templates): modulating delaytime in wasm could crash The modulated delay time was converted to int with i32.trunc_f32_u. This throws runtime error if the modulations caused the delaytime to become negative, because _u implied that it should be unsigned integer and negative numbers were out of range. Using i32.trunc_f32_s fixed this. --- CHANGELOG.md | 2 ++ vm/compiler/templates/wasm/effects.wat | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf1608c..0e3e3ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). x87 stack. ### Fixed +- Modulating delaytime in wasm could crash, because delay time was converted to + int with i32.trunc_f32_u. Using i32.trunc_f32_s fixed this. - When recording notes from VSTI, no track was created for instruments that had no notes triggered, resulting in misalignment of the tracks from instruments. - 32-bit su_load_gmdls clobbered ebx, even though __stdcall demands it to be not diff --git a/vm/compiler/templates/wasm/effects.wat b/vm/compiler/templates/wasm/effects.wat index 82d350d..c492bff 100644 --- a/vm/compiler/templates/wasm/effects.wat +++ b/vm/compiler/templates/wasm/effects.wat @@ -313,7 +313,7 @@ )) {{- end}} {{- if .SupportsModulation "delay" "delaytime"}} - (i32.trunc_f32_u (f32.add + (i32.trunc_f32_s (f32.add (f32.add (local.get $delayTime) (f32.mul @@ -324,7 +324,7 @@ (f32.const 0.5) )) {{- else}} - (i32.trunc_f32_u (f32.add (local.get $delayTime) (f32.const 0.5))) + (i32.trunc_f32_s (f32.add (local.get $delayTime) (f32.const 0.5))) {{- end}} {{- else}} (i32.load16_u