SetRecursionLimit() 공개 메소드

Set the maximum message recursion depth.
In order to prevent malicious messages from causing stack overflows, CodedInputStream limits how deeply messages may be nested. The default limit is 64.
public SetRecursionLimit ( int limit ) : int
limit int
리턴 int
예제 #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));
        }