bytecodealliance / bytecodealliance/wasmtime-dotnet

Extensions are not working properly in NetStandard2.0

Open
#307 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
519
Forks
67
Avg merge
1h 7m
Merged PRs (30d)
1

Description

When passing an empty string as the module name, a `NullReferenceException` is thrown at `System.Text.UTF8Encoding.GetBytes(Char* chars, Int32 charCount, Byte* bytes, Int32 byteCount)` in System.Text\UTF8Encoding.cs:line 433

This comes from the following code
```
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe int GetBytes(this Encoding encoding, string chars, Span bytes)
{
fixed (char* charsPtr = chars)
fixed (byte* bytesPtr = bytes)
{
return encoding.GetBytes(charsPtr, chars.Length, bytesPtr, bytes.Length);
}
}
```
at `Wasmtime.Extensions.GetBytes(Encoding encoding, String chars, Span bytes)` in Wasmtime\Extensions.cs

I'd suggest adding the following at the beginning of the `GetBytes` functions:
```
if (chars.Length == 0 && bytes.Length == 0)
return 0;
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.