From 92cdf87f1a276356657ca1b426c115bff0ad2798 Mon Sep 17 00:00:00 2001 From: Junrou Nishida Date: Mon, 7 Mar 2022 19:46:21 +0900 Subject: [PATCH] [C#] fix parse failure for extensions with large field numbers (#9591) --- .../CodedInputStreamTest.cs | 19 +++++++++++++++++++ csharp/src/Google.Protobuf/WireFormat.cs | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs b/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs index 5e72525fc9..234155975a 100644 --- a/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs @@ -716,6 +716,25 @@ namespace Google.Protobuf } } + [Test] + public void MaximumFieldNumber() + { + MemoryStream ms = new MemoryStream(); + CodedOutputStream output = new CodedOutputStream(ms); + + int fieldNumber = 0x1FFFFFFF; + uint tag = WireFormat.MakeTag(fieldNumber, WireFormat.WireType.LengthDelimited); + output.WriteRawVarint32(tag); + output.WriteString("field 1"); + output.Flush(); + ms.Position = 0; + + CodedInputStream input = new CodedInputStream(ms); + + Assert.AreEqual(tag, input.ReadTag()); + Assert.AreEqual(fieldNumber, WireFormat.GetTagFieldNumber(tag)); + } + [Test] public void Tag0Throws() { diff --git a/csharp/src/Google.Protobuf/WireFormat.cs b/csharp/src/Google.Protobuf/WireFormat.cs index 68f0f4a1f5..201fd16e0d 100644 --- a/csharp/src/Google.Protobuf/WireFormat.cs +++ b/csharp/src/Google.Protobuf/WireFormat.cs @@ -90,7 +90,7 @@ namespace Google.Protobuf /// public static int GetTagFieldNumber(uint tag) { - return (int) tag >> TagTypeBits; + return (int) (tag >> TagTypeBits); } ///