Skip to content

Commit

Permalink
[C#] fix parse failure for extensions with large field numbers (#9591)
Browse files Browse the repository at this point in the history
  • Loading branch information
homuler committed Mar 7, 2022
1 parent 349d74d commit 92cdf87
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs
Expand Up @@ -716,6 +716,25 @@ public void TestSlowPathAvoidance()
}
}

[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()
{
Expand Down
2 changes: 1 addition & 1 deletion csharp/src/Google.Protobuf/WireFormat.cs
Expand Up @@ -90,7 +90,7 @@ public static WireType GetTagWireType(uint tag)
/// </summary>
public static int GetTagFieldNumber(uint tag)
{
return (int) tag >> TagTypeBits;
return (int) (tag >> TagTypeBits);
}

/// <summary>
Expand Down

0 comments on commit 92cdf87

Please sign in to comment.