Skip to content
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

Issue with BinaryReader.ReadString returning wrong value on combo WASM AndroidDevice(not simulator) Chrome AOT #16771

Open
dbriard opened this issue Aug 22, 2024 · 0 comments
Labels

Comments

@dbriard
Copy link
Contributor

dbriard commented Aug 22, 2024

Describe the bug

I found a rather anoying bug on my wasm app but it happen only for the specific combo WASM Android Phone (not simulator) Chrome Aot compilation and that make my website throwing an exception in StartBrowserAppAsync.

Quickly: BinaryReader.ReadString, and especially GetChars method failed to return the correct value on the above combo.
The first 15? first characters of each ReadString are '' so the resource path is only the end of the filename.

This method was use by Avalonia in AssemblyDescriptor class:
image

The exception is a about adding a duplicated key in Linq ToDictionary and I am still not sure where are the duplicated key, but after deep debug, I found a strange issue in .NET BinaryReader.ReadString. I suppose that the duplicated key are empty string because short named resource will be read as empty string due to the bug.

In my browser project, I had a json config file as AvaloniaResource, and the crash happen when Avalonia initialize StandardAssetLoader that read the description of the resources.

The issue is not in Avalonia itself, it is may be in .NET runtime, or in Chrome Android I am not sure.
But it could be fixed in Avalonia if you replace BinaryReader.ReadString that read an UTF8 string by a custom implementation.

All the details of the issue are in this discussion: #16738

To Reproduce

I created a repro project here:
AvaloniaReadStringRepro.zip

And the compiled page here: https://dbriard.github.io/readstring

The repro page do not crash, but if you remote debug it, you will see the problem (I added lot of debug console write).

FI: To remote debug, I activate developer mode on Android Phone, plug my photo to the computer in usb, run Chrome Desktop, and entrer the Url chrome://inspect/#devices

The result in the Inspector Console is :
image
GetChars return "resource.json" instead of "dummy_avalonia_resource.json" because the first chars are all zeros!!!
image

Expected behavior

I would like all BinaryReader.ReadString() calls to be replaced by a working custom implemenation.

Avalonia version

11.1.3

OS

Android

Additional context

The GetChars() bug is only for the specific combo Android WASM Aot Chrome (or Chrome beta)

GetChars() is from Encoding.UTF8.GetDecoder() => _decoder variable in BinaryReader.

I tested on two different android phone and same problem.

On the same android phone, no problem when using Firefox or Edge!
No problem in Android simulator on Windows
No problem on Windows for any browser, no problem on MacOS !

I just can make it work on my android device if I disable AOT compilation... but I require AOT for performance reason.

@dbriard dbriard added the bug label Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant