Skip to content

Commit

Permalink
fix(vm/compiler/templates): modulating delaytime in wasm could crash
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vsariola committed Apr 8, 2024
1 parent f074c39 commit 4a8d4c5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions vm/compiler/templates/wasm/effects.wat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 4a8d4c5

Please sign in to comment.