|
@@ -33,6 +33,7 @@
|
|
using Google.Protobuf.Reflection;
|
|
using Google.Protobuf.Reflection;
|
|
using UnitTest.Issues.TestProtos;
|
|
using UnitTest.Issues.TestProtos;
|
|
using NUnit.Framework;
|
|
using NUnit.Framework;
|
|
|
|
+using System.IO;
|
|
using static UnitTest.Issues.TestProtos.OneofMerging.Types;
|
|
using static UnitTest.Issues.TestProtos.OneofMerging.Types;
|
|
|
|
|
|
namespace Google.Protobuf
|
|
namespace Google.Protobuf
|
|
@@ -90,5 +91,26 @@ namespace Google.Protobuf
|
|
merged.MergeFrom(message2);
|
|
merged.MergeFrom(message2);
|
|
Assert.AreEqual(expected, merged);
|
|
Assert.AreEqual(expected, merged);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // Check that a tag immediately followed by end of limit can still be read.
|
|
|
|
+ [Test]
|
|
|
|
+ public void CodedInputStream_LimitReachedRightAfterTag()
|
|
|
|
+ {
|
|
|
|
+ MemoryStream ms = new MemoryStream();
|
|
|
|
+ var cos = new CodedOutputStream(ms);
|
|
|
|
+ cos.WriteTag(11, WireFormat.WireType.Varint);
|
|
|
|
+ Assert.AreEqual(1, cos.Position);
|
|
|
|
+ cos.WriteString("some extra padding"); // ensure is currentLimit distinct from the end of the buffer.
|
|
|
|
+ cos.Flush();
|
|
|
|
+
|
|
|
|
+ var cis = new CodedInputStream(ms.ToArray());
|
|
|
|
+ cis.PushLimit(1); // make sure we reach the limit right after reading the tag.
|
|
|
|
+
|
|
|
|
+ // we still must read the tag correctly, even though the tag is at the very end of our limited input
|
|
|
|
+ // (which is a corner case and will most likely result in an error when trying to read value of the field
|
|
|
|
+ // decribed by this tag, but it would be a logical error not to read the tag that's actually present).
|
|
|
|
+ // See https://github.com/protocolbuffers/protobuf/pull/7289
|
|
|
|
+ cis.AssertNextTag(WireFormat.MakeTag(11, WireFormat.WireType.Varint));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|