From e0d24cc84a81d236daf0bbf783037c8c8c24d814 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Fri, 11 Aug 2017 10:14:24 +0100 Subject: Detect invalid tags with a field number of 0 in C# Previously we only rejected the tag if the tag itself was 0, i.e. field=0, type=varint. The type doesn't matter: field 0 is always invalid. This removes the last of the C# conformance failures. --- csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs') diff --git a/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs b/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs index e719d2a0..e7c6b805 100644 --- a/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs @@ -284,6 +284,20 @@ namespace Google.Protobuf Assert.Throws(() => input.ReadBytes()); } + // Representations of a tag for field 0 with various wire types + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + [TestCase(3)] + [TestCase(4)] + [TestCase(5)] + public void ReadTag_ZeroFieldRejected(byte tag) + { + CodedInputStream cis = new CodedInputStream(new byte[] { tag }); + Assert.Throws(() => cis.ReadTag()); + } + internal static TestRecursiveMessage MakeRecursiveMessage(int depth) { if (depth == 0) -- cgit v1.2.3