-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bytes: IndexByte can return -4294967295
when memory usage is above 2^31 on js/wasm
#65571
Comments
Looks like an invalid value coming back from |
Possibly! I haven't tried to modify |
I have a reproducible example for this bug. Please take a look at #68395 |
bytes.IndexByte
can return -4294967295
when memory usage is above 2^31-4294967295
when memory usage is above 2^31 on js/wasm
Change https://go.dev/cl/597955 mentions this issue: |
@gopherbot please open backport issues. This bug causes {bytes,string}.Index functions to return wrong results when used with very large arguments. |
Backport issue(s) opened: #68474 (for 1.21), #68475 (for 1.22). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases. |
Here's a simple reproducer.
|
Go version
1.21.7
Output of
go env
in your module/workspace:GOARCH=wasm GOOS=js GOHOSTARCH=amd64 (I'll update this with the values I used when experimenting with a fix when I can)
What did you do?
It seems that
bytes.IndexByte
when compiled tojs/wasm
can return values that are below-1
. The code snippet that triggered this issue is this:(extracted from https://github.com/evanw/esbuild/blob/2af5ccf478812d2d7226ad4435d46fbbb3419a8c/internal/js_printer/js_printer.go#L3464)
Original issue: stackblitz/webcontainer-core#1310
I haven't been able to create a minimal example exhibiting the same behaviour just yet. I'm still working on that. 👈
However the bug randomly appears when memory usage gets near 2^31. I have also verified that the issue is present both in Chrome and Firefox (so this does not appear to be a WASM vm bug)
What did you see happen?
bytes.IndexByte
returns-4294967295
on the following snippet:I've also seen similar values such as
-4294967293
for other input.What did you expect to see?
I expect to see the correct, positive values and no other negative values than
-1
.Note that I did a simple patch modifying:
https://github.com/golang/go/blob/master/src/bytes/bytes.go#L95-L97
to be:
And it did fix the issue as it can be seen there:
https://stackblitz.com/edit/github-9i57jp-wrcype
Again, apologies for the lack of a good and simple reproducible example. I'll try to update this issue as soon as I have found one.
The text was updated successfully, but these errors were encountered: