Skip to content

Commit 05deeac

Browse files
Copilotrkttu
andcommitted
Fix Unicode string null termination in StringToBytes method
Co-authored-by: rkttu <1297346+rkttu@users.noreply.github.com>
1 parent 4e6e5b3 commit 05deeac

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Experimental.System.Messaging/Messaging/Message.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,10 +2416,11 @@ internal static string StringFromBytes(byte[] bytes, int len)
24162416
/// <internalonly/>
24172417
internal static byte[] StringToBytes(string value)
24182418
{
2419-
int size = value.Length * 2 + 1;
2419+
int size = value.Length * 2 + 2;
24202420
byte[] byteBuffer = new byte[size];
2421-
byteBuffer[size - 1] = 0;
24222421
Encoding.Unicode.GetBytes(value.ToCharArray(), 0, value.Length, byteBuffer, 0);
2422+
byteBuffer[size - 2] = 0;
2423+
byteBuffer[size - 1] = 0;
24232424
return byteBuffer;
24242425
}
24252426

0 commit comments

Comments
 (0)