dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.28k stars 4.73k forks source link

[Bug] UTF8 decoder fail to decode a byte array in a WASM app on combo Android ARM + Chrome + AOT #106755

Open dbriard opened 2 months ago

dbriard commented 2 months ago

Description

Hi all, I discoved a strange issue in .NET8. I have a WASM application build using Avalonia framework that was running fine on my platforms (desktop browsers, and android browsers). After I migrated from .NET7 to .NET8, the "website" failed to load on my Android device throwning a exception.

I debugged as deep as I could and found that the problem come from the GetChars function in Encoding.UTF8.GetDecoder().

The function is used by ReadString() of BinaryReader.

Here my debug output on platforms that works: image

And here is the same on my android phone using Chrome latest version. image

The 15 first characters are not read correctly! I read severals strings, and for each strings the first 15 characters are 0.

What is really strange, is that on the same device, there is no problem when I run the website on Edge browser. Same issue on a different phone.

Here more tests:

Android device 1/Chrome => BUG Android device 2/Chrome => BUG Android device 1/Chrome BETA => BUG Android simulator on Windows 11/Chrome => work Android device 1/Edge => work Windows11/Edge => work Windows11/Firefox => work Windows11/Chrome => work

My code is compiled using AOT.

Reproduction Steps

Try to decode the following byte array on a WASM app (AOT?) on Android physical device in Chrome browser.

image

Expected behavior

The result should be:

image

Actual behavior

The 15 first chars are 0 on android device using chrome.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

I cannot debug more deeper as the code is not accessible: image

dbriard commented 2 months ago

Additional details:

I tried without AOT compilation and the problem do not happen. So far, GetChars only fail on .NET8 + Android real device + Chrome + AOT compilation.

I also tested on Firefox android, no problem, and on iPhone (Safari and Chrome), no problem...

So in the end, not sure if the issue is in .NET8 or Chrome ARM on android...

If you need additionnal info, let me know.

dotnet-policy-service[bot] commented 2 months ago

Tagging subscribers to 'arch-wasm': @lewing See info in area-owners.md if you want to be subscribed.

dotnet-policy-service[bot] commented 2 months ago

Tagging subscribers to this area: @dotnet/area-system-globalization See info in area-owners.md if you want to be subscribed.

dotnet-policy-service[bot] commented 2 months ago

Tagging subscribers to this area: @dotnet/area-system-text-encoding See info in area-owners.md if you want to be subscribed.

dotnet-policy-service[bot] commented 2 months ago

Tagging subscribers to 'arch-android': @vitek-karas, @simonrozsival, @steveisok, @akoeplinger See info in area-owners.md if you want to be subscribed.

tarekgh commented 2 months ago

CC @lewing

lewing commented 1 month ago

I think this is probabaly a chrome issue where there is a bug when running wasm on a 32bit build, Chrome on android is shipped as a 32 bit executable by default. All the scenarios where chrome works are 64 bit builds.

@kg what is the best way to file issues like this?