Skip to content

Commit 8a1aeb3

Browse files
authored
Merge pull request #22126 from ramezgerges/wasm_segfault
fix(wasm): out of memory access when calling ubrk_open
2 parents 692452b + 9bdf239 commit 8a1aeb3

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/Directory.Build.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<MicrosoftTestingPlatformVersion>1.9.0</MicrosoftTestingPlatformVersion>
7777
<SkiaSharpVersion>3.119.0</SkiaSharpVersion>
7878
<HarfbuzzSharpVersion>8.3.1.1</HarfbuzzSharpVersion>
79-
<UnoICUVersion>77.1.0-dev.45</UnoICUVersion>
79+
<UnoICUVersion>77.1.0-dev.46</UnoICUVersion>
8080
</PropertyGroup>
8181

8282
<ItemGroup>

src/Uno.UI/UI/Xaml/Documents/UnicodeText.ICU.skia.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,15 @@ static unsafe ICU()
9696
.Where(t => t.Item2 != null)
9797
.Select(t => t.a.GetManifestResourceStream(t.Item2!))
9898
.First()!;
99-
var data = new byte[stream.Length];
100-
stream.ReadExactly(data, 0, data.Length);
101-
fixed (byte* dataPtr = data)
99+
// udata_setCommonData does not copy the buffer, so it needs to be pinned.
100+
// For alignment, the ICU docs require 16-byte alignment. https://unicode-org.github.io/icu/userguide/icu_data/#alignment
101+
var data = NativeMemory.AlignedAlloc((UIntPtr)stream.Length, 16);
102+
stream.ReadExactly(new Span<byte>(data, (int)stream.Length));
103+
var errorPtr = BrowserICUSymbols.uno_udata_setCommonData((IntPtr)data);
104+
var errorString = Marshal.PtrToStringUTF8(errorPtr);
105+
if (errorString is not null)
102106
{
103-
var errorPtr = BrowserICUSymbols.uno_udata_setCommonData((IntPtr)dataPtr);
104-
var errorString = Marshal.PtrToStringUTF8(errorPtr);
105-
if (errorString is not null)
106-
{
107-
throw new InvalidOperationException($"uno_udata_setCommonData failed: {errorString}");
108-
}
107+
throw new InvalidOperationException($"uno_udata_setCommonData failed: {errorString}");
109108
}
110109

111110
// ICU is included in the dotnet runtime itself

0 commit comments

Comments
 (0)