aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--conformance/failure_list_csharp.txt5
-rw-r--r--csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs14
-rw-r--r--csharp/src/Google.Protobuf/CodedInputStream.cs4
3 files changed, 16 insertions, 7 deletions
diff --git a/conformance/failure_list_csharp.txt b/conformance/failure_list_csharp.txt
index 55e63922..e69de29b 100644
--- a/conformance/failure_list_csharp.txt
+++ b/conformance/failure_list_csharp.txt
@@ -1,5 +0,0 @@
-Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_0
-Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_1
-Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_2
-Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_3
-
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<InvalidProtocolBufferException>(() => 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<InvalidProtocolBufferException>(() => cis.ReadTag());
+ }
+
internal static TestRecursiveMessage MakeRecursiveMessage(int depth)
{
if (depth == 0)
diff --git a/csharp/src/Google.Protobuf/CodedInputStream.cs b/csharp/src/Google.Protobuf/CodedInputStream.cs
index 84f90a25..abd352b9 100644
--- a/csharp/src/Google.Protobuf/CodedInputStream.cs
+++ b/csharp/src/Google.Protobuf/CodedInputStream.cs
@@ -373,9 +373,9 @@ namespace Google.Protobuf
lastTag = ReadRawVarint32();
}
- if (lastTag == 0)
+ if (WireFormat.GetTagFieldNumber(lastTag) == 0)
{
- // If we actually read zero, that's not a valid tag.
+ // If we actually read a tag with a field of 0, that's not a valid tag.
throw InvalidProtocolBufferException.InvalidTag();
}
return lastTag;