示例#1
0
        public void MaliciousRecursion()
        {
            ByteString data64 = MakeRecursiveMessage(64).ToByteString();
            ByteString data65 = MakeRecursiveMessage(65).ToByteString();

            AssertMessageDepth(TestRecursiveMessage.ParseFrom(data64), 64);

            try
            {
                TestRecursiveMessage.ParseFrom(data65);
                Assert.Fail("Should have thrown an exception!");
            }
            catch (InvalidProtocolBufferException)
            {
                // success.
            }

            CodedInputStream input = data64.CreateCodedInput();

            input.SetRecursionLimit(8);
            try
            {
                TestRecursiveMessage.ParseFrom(input);
                Assert.Fail("Should have thrown an exception!");
            }
            catch (InvalidProtocolBufferException)
            {
                // success.
            }
        }
示例#2
0
        public void MaliciousRecursion()
        {
            ByteString data64 = MakeRecursiveMessage(64).ToByteString();
            ByteString data65 = MakeRecursiveMessage(65).ToByteString();

            AssertMessageDepth(TestRecursiveMessage.ParseFrom(data64), 64);

            Assert.Throws <InvalidProtocolBufferException>(() => TestRecursiveMessage.ParseFrom(data65));

            CodedInputStream input = data64.CreateCodedInput();

            input.SetRecursionLimit(8);
            Assert.Throws <InvalidProtocolBufferException>(() => TestRecursiveMessage.ParseFrom(input));
        }