runtime: off-by-one-error in wasmTruncS and wasmTruncU causes a crash #38839
Labels
arch-wasm
WebAssembly issues
FrozenDueToAge
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, this is the latest release.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
This is a reduced test case from a real-world issue: evanw/esbuild#83.
The contents of main.go:
Compile with this:
Run with this, where
[number]
is the number to test:What did you expect to see?
This program should never crash.
What did you see instead?
This program crashes on the following inputs:
0x7fff_ffff_ffff_ffff
) for the cast to int64 (i.e.runtime.wasmTruncS
)0xffff_ffff_ffff_ffff
) for the cast to unt64 (i.e.runtime.wasmTruncU
)I believe the problem is that these runtime functions check their upper bounds with
F64Gt
(greater than) but they should check withF64Ge
(greater than or equal to) instead.The problem is that these values are outside the range where 64-bit floats can represent every integer, so
0x7fff_ffff_ffff_ffff
is the same floating-point value as0x8000_0000_0000_0000
(and many other nearby integers). Basically many integers both inside and outside the range map to that same floating-point value. It looks like all major JavaScript VMs consider that floating-point value outside the range and throw an exception.The check for the lower bounds appears to be correct.
The text was updated successfully, but these errors were encountered: