Skip to content

Commit 3bdb2c1

Browse files
Update MessagePack version (#47790)
1 parent 3b091f7 commit 3bdb2c1

File tree

7 files changed

+57
-21
lines changed

7 files changed

+57
-21
lines changed

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@
268268
<DuendeIdentityServerVersion>6.0.4</DuendeIdentityServerVersion>
269269
<DuendeIdentityServerStorageVersion>6.0.4</DuendeIdentityServerStorageVersion>
270270
<DuendeIdentityServerEntityFrameworkStorageVersion>6.0.4</DuendeIdentityServerEntityFrameworkStorageVersion>
271-
<MessagePackVersion>2.1.90</MessagePackVersion>
271+
<MessagePackVersion>2.5.108</MessagePackVersion>
272272
<MicrosoftIdentityWebVersion>1.16.0</MicrosoftIdentityWebVersion>
273273
<MicrosoftIdentityWebMicrosoftGraphVersion>1.16.0</MicrosoftIdentityWebMicrosoftGraphVersion>
274274
<MicrosoftIdentityWebUIVersion>1.16.0</MicrosoftIdentityWebUIVersion>

src/Components/Server/src/BlazorPack/BlazorPackHubProtocolWorker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Components.Server.BlazorPack;
1010

1111
internal sealed class BlazorPackHubProtocolWorker : MessagePackHubProtocolWorker
1212
{
13-
protected override object DeserializeObject(ref MessagePackReader reader, Type type, string field)
13+
protected override object? DeserializeObject(ref MessagePackReader reader, Type type, string field)
1414
{
1515
try
1616
{

src/SignalR/common/Protocols.MessagePack/src/Protocol/DefaultMessagePackHubProtocolWorker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public DefaultMessagePackHubProtocolWorker(MessagePackSerializerOptions messageP
1616
_messagePackSerializerOptions = messagePackSerializerOptions;
1717
}
1818

19-
protected override object DeserializeObject(ref MessagePackReader reader, Type type, string field)
19+
protected override object? DeserializeObject(ref MessagePackReader reader, Type type, string field)
2020
{
2121
try
2222
{

src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocolWorker.cs

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ private HubMessage CreateInvocationMessage(ref MessagePackReader reader, IInvoca
7979
}
8080

8181
var target = ReadString(ref reader, binder, "target");
82+
ThrowIfNullOrEmpty(target, "target for Invocation message");
8283

83-
object[]? arguments;
84+
object?[]? arguments;
8485
try
8586
{
8687
var parameterTypes = binder.GetParameterTypes(target);
@@ -105,9 +106,12 @@ private HubMessage CreateStreamInvocationMessage(ref MessagePackReader reader, I
105106
{
106107
var headers = ReadHeaders(ref reader);
107108
var invocationId = ReadInvocationId(ref reader);
109+
ThrowIfNullOrEmpty(invocationId, "invocation ID for StreamInvocation message");
110+
108111
var target = ReadString(ref reader, "target");
112+
ThrowIfNullOrEmpty(target, "target for StreamInvocation message");
109113

110-
object[] arguments;
114+
object?[] arguments;
111115
try
112116
{
113117
var parameterTypes = binder.GetParameterTypes(target);
@@ -132,7 +136,9 @@ private HubMessage CreateStreamItemMessage(ref MessagePackReader reader, IInvoca
132136
{
133137
var headers = ReadHeaders(ref reader);
134138
var invocationId = ReadInvocationId(ref reader);
135-
object value;
139+
ThrowIfNullOrEmpty(invocationId, "invocation ID for StreamItem message");
140+
141+
object? value;
136142
try
137143
{
138144
var itemType = binder.GetStreamItemType(invocationId);
@@ -150,6 +156,8 @@ private CompletionMessage CreateCompletionMessage(ref MessagePackReader reader,
150156
{
151157
var headers = ReadHeaders(ref reader);
152158
var invocationId = ReadInvocationId(ref reader);
159+
ThrowIfNullOrEmpty(invocationId, "invocation ID for Completion message");
160+
153161
var resultKind = ReadInt32(ref reader, "resultKind");
154162

155163
string? error = null;
@@ -202,6 +210,8 @@ private static CancelInvocationMessage CreateCancelInvocationMessage(ref Message
202210
{
203211
var headers = ReadHeaders(ref reader);
204212
var invocationId = ReadInvocationId(ref reader);
213+
ThrowIfNullOrEmpty(invocationId, "invocation ID for CancelInvocation message");
214+
205215
return ApplyHeaders(headers, new CancelInvocationMessage(invocationId));
206216
}
207217

@@ -234,7 +244,11 @@ private static CloseMessage CreateCloseMessage(ref MessagePackReader reader, int
234244
for (var i = 0; i < headerCount; i++)
235245
{
236246
var key = ReadString(ref reader, $"headers[{i}].Key");
247+
ThrowIfNullOrEmpty(key, "key in header");
248+
237249
var value = ReadString(ref reader, $"headers[{i}].Value");
250+
ThrowIfNullOrEmpty(value, "value in header");
251+
238252
headers.Add(key, value);
239253
}
240254
return headers;
@@ -255,14 +269,17 @@ private static CloseMessage CreateCloseMessage(ref MessagePackReader reader, int
255269
streams = new List<string>();
256270
for (var i = 0; i < streamIdCount; i++)
257271
{
258-
streams.Add(reader.ReadString());
272+
var id = reader.ReadString();
273+
ThrowIfNullOrEmpty(id, "value in streamIds received");
274+
275+
streams.Add(id);
259276
}
260277
}
261278

262279
return streams?.ToArray();
263280
}
264281

265-
private object[] BindArguments(ref MessagePackReader reader, IReadOnlyList<Type> parameterTypes)
282+
private object?[] BindArguments(ref MessagePackReader reader, IReadOnlyList<Type> parameterTypes)
266283
{
267284
var argumentCount = ReadArrayLength(ref reader, "arguments");
268285

@@ -274,7 +291,7 @@ private object[] BindArguments(ref MessagePackReader reader, IReadOnlyList<Type>
274291

275292
try
276293
{
277-
var arguments = new object[argumentCount];
294+
var arguments = new object?[argumentCount];
278295
for (var i = 0; i < argumentCount; i++)
279296
{
280297
arguments[i] = DeserializeObject(ref reader, parameterTypes[i], "argument");
@@ -288,7 +305,7 @@ private object[] BindArguments(ref MessagePackReader reader, IReadOnlyList<Type>
288305
}
289306
}
290307

291-
protected abstract object DeserializeObject(ref MessagePackReader reader, Type type, string field);
308+
protected abstract object? DeserializeObject(ref MessagePackReader reader, Type type, string field);
292309

293310
private static T ApplyHeaders<T>(IDictionary<string, string>? source, T destination) where T : HubInvocationMessage
294311
{
@@ -558,7 +575,7 @@ private static void PackHeaders(IDictionary<string, string>? headers, ref Messag
558575
}
559576
}
560577

561-
private static string ReadInvocationId(ref MessagePackReader reader) =>
578+
private static string? ReadInvocationId(ref MessagePackReader reader) =>
562579
ReadString(ref reader, "invocationId");
563580

564581
private static bool ReadBoolean(ref MessagePackReader reader, string field)
@@ -585,7 +602,7 @@ private static int ReadInt32(ref MessagePackReader reader, string field)
585602
}
586603
}
587604

588-
protected static string ReadString(ref MessagePackReader reader, IInvocationBinder binder, string field)
605+
protected static string? ReadString(ref MessagePackReader reader, IInvocationBinder binder, string field)
589606
{
590607
try
591608
{
@@ -605,7 +622,7 @@ protected static string ReadString(ref MessagePackReader reader, IInvocationBind
605622
}
606623
}
607624

608-
protected static string ReadString(ref MessagePackReader reader, string field)
625+
protected static string? ReadString(ref MessagePackReader reader, string field)
609626
{
610627
try
611628
{
@@ -640,4 +657,12 @@ private static long ReadArrayLength(ref MessagePackReader reader, string field)
640657
throw new InvalidDataException($"Reading array length for '{field}' failed.", ex);
641658
}
642659
}
660+
661+
private static void ThrowIfNullOrEmpty([NotNull] string? target, string message)
662+
{
663+
if (string.IsNullOrEmpty(target))
664+
{
665+
throw new InvalidDataException($"Null or empty {message}.");
666+
}
667+
}
643668
}

src/SignalR/common/SignalR.Common/test/Internal/Protocol/MessagePackHubProtocolTestBase.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,21 +279,28 @@ protected void TestWriteMessages(ProtocolTestData testData)
279279
new InvalidMessageData("HeaderValueInt", new byte[] { 0x92, 1, 0x82, 0xa3, (byte)'f', (byte)'o', (byte)'o', 42 }, "Reading 'headers[0].Value' as String failed."),
280280
new InvalidMessageData("HeaderKeyArray", new byte[] { 0x92, 1, 0x84, 0xa3, (byte)'f', (byte)'o', (byte)'o', 0xa3, (byte)'f', (byte)'o', (byte)'o', 0x90, 0xa3, (byte)'f', (byte)'o', (byte)'o' }, "Reading 'headers[1].Key' as String failed."),
281281
new InvalidMessageData("HeaderValueArray", new byte[] { 0x92, 1, 0x84, 0xa3, (byte)'f', (byte)'o', (byte)'o', 0xa3, (byte)'f', (byte)'o', (byte)'o', 0xa3, (byte)'f', (byte)'o', (byte)'o', 0x90 }, "Reading 'headers[1].Value' as String failed."),
282+
new InvalidMessageData("HeaderKeyEmptyString", new byte[] { 0x92, 1, 0x82, 0xa0, 0xa3, (byte)'f', (byte)'o', (byte)'o' }, "Null or empty key in header."),
283+
new InvalidMessageData("HeaderValueEmptyString", new byte[] { 0x92, 1, 0x82, 0xa3, (byte)'f', (byte)'o', (byte)'o', 0xa0 }, "Null or empty value in header."),
282284

283285
// InvocationMessage
284286
new InvalidMessageData("InvocationMissingId", new byte[] { 0x92, 1, 0x80 }, "Reading 'invocationId' as String failed."),
285287
new InvalidMessageData("InvocationIdBoolean", new byte[] { 0x91, 1, 0x80, 0xc2 }, "Reading 'invocationId' as String failed."),
286288
new InvalidMessageData("InvocationTargetMissing", new byte[] { 0x93, 1, 0x80, 0xa3, (byte)'a', (byte)'b', (byte)'c' }, "Reading 'target' as String failed."),
287289
new InvalidMessageData("InvocationTargetInt", new byte[] { 0x94, 1, 0x80, 0xa3, (byte)'a', (byte)'b', (byte)'c', 42 }, "Reading 'target' as String failed."),
290+
new InvalidMessageData("InvocationTargetEmptyString", new byte[] { 0x94, 1, 0x80, 0xa3, (byte)'a', (byte)'b', (byte)'c', 0xa0 }, "Null or empty target for Invocation message."),
291+
new InvalidMessageData("InvocationEmptyStringStreamId", new byte[] { 0x96, 1, 0x80, 0xa3, (byte)'a', (byte)'b', (byte)'c', 0xa1, (byte)'T', 0x91, 0xa0, 0x91, 0xa0 }, "Null or empty value in streamIds received."),
288292

289293
// StreamInvocationMessage
290294
new InvalidMessageData("StreamInvocationMissingId", new byte[] { 0x92, 4, 0x80 }, "Reading 'invocationId' as String failed."),
295+
new InvalidMessageData("StreamInvocationEmptyStringId", new byte[] { 0x93, 4, 0x80, 0xa0 }, "Null or empty invocation ID for StreamInvocation message."),
291296
new InvalidMessageData("StreamInvocationIdBoolean", new byte[] { 0x93, 4, 0x80, 0xc2 }, "Reading 'invocationId' as String failed."),
292297
new InvalidMessageData("StreamInvocationTargetMissing", new byte[] { 0x93, 4, 0x80, 0xa3, (byte)'a', (byte)'b', (byte)'c' }, "Reading 'target' as String failed."),
293298
new InvalidMessageData("StreamInvocationTargetInt", new byte[] { 0x94, 4, 0x80, 0xa3, (byte)'a', (byte)'b', (byte)'c', 42 }, "Reading 'target' as String failed."),
299+
new InvalidMessageData("StreamInvocationTargetEmptyString", new byte[] { 0x94, 4, 0x80, 0xa3, (byte)'a', (byte)'b', (byte)'c', 0xa0 }, "Null or empty target for StreamInvocation message."),
294300

295301
// StreamItemMessage
296302
new InvalidMessageData("StreamItemMissingId", new byte[] { 0x92, 2, 0x80 }, "Reading 'invocationId' as String failed."),
303+
new InvalidMessageData("StreamItemEmptyStringId", new byte[] { 0x93, 2, 0x80, 0xa0 }, "Null or empty invocation ID for StreamItem message."),
297304
new InvalidMessageData("StreamItemInvocationIdBoolean", new byte[] { 0x93, 2, 0x80, 0xc2 }, "Reading 'invocationId' as String failed."),
298305

299306
// These now trigger StreamBindingInvocationFailureMessages
@@ -302,6 +309,7 @@ protected void TestWriteMessages(ProtocolTestData testData)
302309

303310
// CompletionMessage
304311
new InvalidMessageData("CompletionMissingId", new byte[] { 0x92, 3, 0x80 }, "Reading 'invocationId' as String failed."),
312+
new InvalidMessageData("CompletionEmptyStringId", new byte[] { 0x93, 3, 0x80, 0xa0 }, "Null or empty invocation ID for Completion message."),
305313
new InvalidMessageData("CompletionIdBoolean", new byte[] { 0x93, 3, 0x80, 0xc2 }, "Reading 'invocationId' as String failed."),
306314
new InvalidMessageData("CompletionResultKindString", new byte[] { 0x94, 3, 0x80, 0xa3, (byte)'x', (byte)'y', (byte)'z', 0xa3, (byte)'x', (byte)'y', (byte)'z' }, "Reading 'resultKind' as Int32 failed."),
307315
new InvalidMessageData("CompletionResultKindOutOfRange", new byte[] { 0x94, 3, 0x80, 0xa3, (byte)'x', (byte)'y', (byte)'z', 42 }, "Invalid invocation result kind."),
@@ -311,6 +319,10 @@ protected void TestWriteMessages(ProtocolTestData testData)
311319
// These now result in CompletionMessages with the error field set
312320
//new InvalidMessageData("CompletionResultMissing", new byte[] { 0x94, 3, 0x80, 0xa3, (byte)'x', (byte)'y', (byte)'z', 0x03 }, "Deserializing object of the `String` type for 'argument' failed."),
313321
//new InvalidMessageData("CompletionResultTypeMismatch", new byte[] { 0x95, 3, 0x80, 0xa3, (byte)'x', (byte)'y', (byte)'z', 0x03, 42 }, "Deserializing object of the `String` type for 'argument' failed."),
322+
323+
// CancelInvocationMessage
324+
new InvalidMessageData("CancelInvocationMissingId", new byte[] { 0x92, 5, 0x80 }, "Reading 'invocationId' as String failed."),
325+
new InvalidMessageData("CancelInvocationEmptyStringId", new byte[] { 0x93, 5, 0x80, 0xa0 }, "Null or empty invocation ID for CancelInvocation message."),
314326
}.ToDictionary(t => t.Name);
315327

316328
public static IEnumerable<object[]> BaseInvalidPayloadNames => BaseInvalidPayloads.Keys.Select(name => new object[] { name });

src/SignalR/server/SignalR/test/HubConnectionHandlerTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2592,8 +2592,7 @@ private class StringFormatter<T> : IMessagePackFormatter<T>
25922592
{
25932593
public T Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
25942594
{
2595-
// this method isn't used in our tests
2596-
return default;
2595+
return (T)(object)reader.ReadString();
25972596
}
25982597

25992598
public void Serialize(ref MessagePackWriter writer, T value, MessagePackSerializerOptions options)

src/SignalR/server/StackExchangeRedis/src/Internal/RedisProtocol.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public static RedisInvocation ReadInvocation(ReadOnlyMemory<byte> data)
184184
var ids = new string[idCount];
185185
for (var i = 0; i < idCount; i++)
186186
{
187-
ids[i] = reader.ReadString();
187+
ids[i] = reader.ReadString()!;
188188
}
189189

190190
excludedConnectionIds = ids;
@@ -210,10 +210,10 @@ public static RedisGroupCommand ReadGroupCommand(ReadOnlyMemory<byte> data)
210210
ValidateArraySize(ref reader, 5, "GroupCommand");
211211

212212
var id = reader.ReadInt32();
213-
var serverName = reader.ReadString();
213+
var serverName = reader.ReadString()!;
214214
var action = (GroupAction)reader.ReadByte();
215-
var groupName = reader.ReadString();
216-
var connectionId = reader.ReadString();
215+
var groupName = reader.ReadString()!;
216+
var connectionId = reader.ReadString()!;
217217

218218
return new RedisGroupCommand(id, serverName, action, groupName, connectionId);
219219
}
@@ -252,7 +252,7 @@ public static SerializedHubMessage ReadSerializedHubMessage(ref MessagePackReade
252252
var serializations = new SerializedMessage[count];
253253
for (var i = 0; i < count; i++)
254254
{
255-
var protocol = reader.ReadString();
255+
var protocol = reader.ReadString()!;
256256
var serialized = reader.ReadBytes()?.ToArray() ?? Array.Empty<byte>();
257257

258258
serializations[i] = new SerializedMessage(protocol, serialized);
@@ -267,7 +267,7 @@ public static RedisCompletion ReadCompletion(ReadOnlyMemory<byte> data)
267267
var reader = new MessagePackReader(data);
268268
ValidateArraySize(ref reader, 2, "CompletionMessage");
269269

270-
var protocolName = reader.ReadString();
270+
var protocolName = reader.ReadString()!;
271271
var ros = reader.ReadBytes();
272272
return new RedisCompletion(protocolName, ros ?? new ReadOnlySequence<byte>());
273273
}

0 commit comments

Comments
 (0)