CreateWithLimits() public static method

Creates a CodedInputStream with the specified size and recursion limits, reading from an input stream.
This method exists separately from the constructor to reduce the number of constructor overloads. It is likely to be used considerably less frequently than the constructors, as the default limits are suitable for most use cases.
public static CreateWithLimits ( Stream input, int sizeLimit, int recursionLimit ) : CodedInputStream
input Stream The input stream to read from
sizeLimit int The total limit of data to read from the stream.
recursionLimit int The maximum recursion depth to allow while reading.
return CodedInputStream
コード例 #1
0
        public void CreateWithLimits_InvalidLimits()
        {
            var stream = new MemoryStream();

            Assert.Throws <ArgumentOutOfRangeException>(() => CodedInputStream.CreateWithLimits(stream, 0, 1));
            Assert.Throws <ArgumentOutOfRangeException>(() => CodedInputStream.CreateWithLimits(stream, 1, 0));
        }
コード例 #2
0
        public void SizeLimit()
        {
            // Have to use a Stream rather than ByteString.CreateCodedInput as SizeLimit doesn't
            // apply to the latter case.
            MemoryStream     ms    = new MemoryStream(SampleMessages.CreateFullTestAllTypes().ToByteArray());
            CodedInputStream input = CodedInputStream.CreateWithLimits(ms, 16, 100);

            Assert.Throws <InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseFrom(input));
        }
コード例 #3
0
        public void MaliciousRecursion()
        {
            ByteString atRecursiveLimit     = MakeRecursiveMessage(CodedInputStream.DefaultRecursionLimit).ToByteString();
            ByteString beyondRecursiveLimit = MakeRecursiveMessage(CodedInputStream.DefaultRecursionLimit + 1).ToByteString();

            AssertMessageDepth(TestRecursiveMessage.Parser.ParseFrom(atRecursiveLimit), CodedInputStream.DefaultRecursionLimit);

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

            CodedInputStream input = CodedInputStream.CreateWithLimits(new MemoryStream(atRecursiveLimit.ToByteArray()), 1000000, CodedInputStream.DefaultRecursionLimit - 1);

            Assert.Throws <InvalidProtocolBufferException>(() => TestRecursiveMessage.Parser.ParseFrom(input));
        }
コード例 #4
0
        public void MaliciousRecursion()
        {
            ByteString data64 = MakeRecursiveMessage(64).ToByteString();
            ByteString data65 = MakeRecursiveMessage(65).ToByteString();

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

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

            CodedInputStream input = CodedInputStream.CreateWithLimits(new MemoryStream(data64.ToByteArray()), 1000000, 63);

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