From 1e649b6338669d32c92bc882af968f68e4c14896 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 19 Aug 2021 15:46:07 +0200 Subject: [Mono.Profiler.Aot] Write true string wire length (#21196) In some cases, it seems like Mono.Profiler.Aot `ProfileWriter` can produce custom profiles that are unable to be read by `ProfileReader` (or `aot-compiler.c`). There are a few reports [here](https://github.com/xamarin/xamarin-android/issues/4602#issuecomment-618201419). I investigated and found a cause may be the writing of incorrect string length markers in situations where `String.Length` is less than the encoded byte length. In that kind of case, the reader falls out of sync with the record structure and quickly fails. [Here is an example dependency](https://www.fuget.org/packages/AuroraControls.Core/1.2020.520.2/lib/netstandard2.0/Aurora.dll) with members that can produce the issue (I guess the odd characters are caused by obfuscation). ![image](https://user-images.githubusercontent.com/7392704/129899400-086a6e8a-373c-4601-837a-5255e7f93d82.png) I don't think the change requires a profile format version bump, as the format itself is unchanged. Co-authored-by: Ryan Davis --- mcs/class/Mono.Profiler.Log/Mono.Profiler.Aot/ProfileWriter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mcs/class/Mono.Profiler.Log/Mono.Profiler.Aot/ProfileWriter.cs b/mcs/class/Mono.Profiler.Log/Mono.Profiler.Aot/ProfileWriter.cs index e7be91e19d6..4c202900896 100644 --- a/mcs/class/Mono.Profiler.Log/Mono.Profiler.Aot/ProfileWriter.cs +++ b/mcs/class/Mono.Profiler.Log/Mono.Profiler.Aot/ProfileWriter.cs @@ -25,8 +25,8 @@ namespace Mono.Profiler.Aot { void WriteString (string str) { - WriteInt32 (str.Length); var buf = Encoding.UTF8.GetBytes (str); + WriteInt32 (buf.Length); stream.Write (buf, 0, buf.Length); } -- cgit v1.2.3