Пример #1
0
        public void TestParseMessagesCloseTo2G()
        {
            byte[] serializedMessage = GenerateBigSerializedMessage();
            // How many of these big messages do we need to take us near our 2GB limit?
            int count = int.MaxValue / serializedMessage.Length;

            // Now make a MemoryStream that will fake a near-2GB stream of messages by returning
            // our big serialized message 'count' times.
            using var stream = new RepeatingMemoryStream(serializedMessage, count);
            Assert.DoesNotThrow(() => TestAllTypes.Parser.ParseFrom(stream));
        }
Пример #2
0
        public void TestParseMessagesOver2G()
        {
            byte[] serializedMessage = GenerateBigSerializedMessage();
            // How many of these big messages do we need to take us near our 2GB limit?
            int count = int.MaxValue / serializedMessage.Length;

            // Now add one to take us over the 2GB limit
            count++;
            // Now make a MemoryStream that will fake a near-2GB stream of messages by returning
            // our big serialized message 'count' times.
            using var stream = new RepeatingMemoryStream(serializedMessage, count);
            Assert.Throws <InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseFrom(stream),
                                                           "Protocol message was too large.  May be malicious.  " +
                                                           "Use CodedInputStream.SetSizeLimit() to increase the size limit.");
        }