Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C#] fix parse failure for extensions with large field numbers #9591

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, that was a subtle bug. Thanks for catching it.

}

/// <summary>
Expand Down