Beispiel #1
0
 public StringDecoder(int sizeQuota)
 {
     this.sizeQuota    = sizeQuota;
     this.sizeDecoder  = new IntDecoder();
     this.currentState = State.ReadingSize;
     this.Reset();
 }
Beispiel #2
0
 public StringDecoder(int sizeQuota)
 {
     _sizeQuota    = sizeQuota;
     _sizeDecoder  = new IntDecoder();
     _currentState = State.ReadingSize;
     Reset();
 }
 public StringDecoder(int sizeQuota)
 {
     this.sizeQuota = sizeQuota;
     this.sizeDecoder = new IntDecoder();
     this.currentState = State.ReadingSize;
     this.Reset();
 }
 public ServerSessionDecoder(long streamPosition, int maxViaLength, int maxContentTypeLength) : base(streamPosition)
 {
     this.viaDecoder         = new ViaStringDecoder(maxViaLength);
     this.contentTypeDecoder = new ContentTypeStringDecoder(maxContentTypeLength);
     this.sizeDecoder        = new IntDecoder();
     this.currentState       = State.ReadingViaRecord;
 }
Beispiel #5
0
 public ClientDuplexDecoder(long streamPosition)
     : base(streamPosition)
 {
     _sizeDecoder = new IntDecoder();
 }
Beispiel #6
0
 public SingletonMessageDecoder(long streamPosition)
     : base(streamPosition)
 {
     _sizeDecoder  = new IntDecoder();
     _currentState = State.ChunkStart;
 }
            private ArraySegment <byte> ExtractSessionInformationFromMessage(ArraySegment <byte> messageData)
            {
                int num3;
                int num4;

                if (this.isReaderSessionInvalid)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(System.ServiceModel.SR.GetString("BinaryEncoderSessionInvalid")));
                }
                byte[] array = messageData.Array;
                bool   flag  = true;

                try
                {
                    IntDecoder decoder = new IntDecoder();
                    int        num2    = decoder.Decode(array, messageData.Offset, messageData.Count);
                    int        num     = decoder.Value;
                    if (num > messageData.Count)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(System.ServiceModel.SR.GetString("BinaryEncoderSessionMalformed")));
                    }
                    num3 = (messageData.Offset + num2) + num;
                    num4 = (messageData.Count - num2) - num;
                    if (num4 < 0)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(System.ServiceModel.SR.GetString("BinaryEncoderSessionMalformed")));
                    }
                    if (num > 0)
                    {
                        if (num > this.remainingReaderSessionSize)
                        {
                            string    message        = System.ServiceModel.SR.GetString("BinaryEncoderSessionTooLarge", new object[] { this.maxSessionSize });
                            Exception innerException = new QuotaExceededException(message);
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(message, innerException));
                        }
                        this.remainingReaderSessionSize -= num;
                        int size   = num;
                        int offset = messageData.Offset + num2;
                        while (size > 0)
                        {
                            decoder.Reset();
                            int num7  = decoder.Decode(array, offset, size);
                            int count = decoder.Value;
                            offset += num7;
                            size   -= num7;
                            if (count > size)
                            {
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(System.ServiceModel.SR.GetString("BinaryEncoderSessionMalformed")));
                            }
                            string str2 = Encoding.UTF8.GetString(array, offset, count);
                            offset += count;
                            size   -= count;
                            this.readerSession.Add(this.idCounter, str2);
                            this.idCounter++;
                        }
                    }
                    flag = false;
                }
                finally
                {
                    if (flag)
                    {
                        this.isReaderSessionInvalid = true;
                    }
                }
                return(new ArraySegment <byte>(array, num3, num4));
            }
Beispiel #8
0
            private ArraySegment<byte> ExtractSessionInformationFromMessage(ArraySegment<byte> messageData)
            {
                if (_isReaderSessionInvalid)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(SR.BinaryEncoderSessionInvalid));
                }

                byte[] buffer = messageData.Array;
                int dictionarySize;
                int headerSize;
                int newOffset;
                int newSize;
                bool throwing = true;
                try
                {
                    IntDecoder decoder = new IntDecoder();
                    headerSize = decoder.Decode(buffer, messageData.Offset, messageData.Count);
                    dictionarySize = decoder.Value;
                    if (dictionarySize > messageData.Count)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(SR.BinaryEncoderSessionMalformed));
                    }
                    newOffset = messageData.Offset + headerSize + dictionarySize;
                    newSize = messageData.Count - headerSize - dictionarySize;
                    if (newSize < 0)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(SR.BinaryEncoderSessionMalformed));
                    }
                    if (dictionarySize > 0)
                    {
                        if (dictionarySize > _remainingReaderSessionSize)
                        {
                            string message = SR.Format(SR.BinaryEncoderSessionTooLarge, _maxSessionSize);
                            if (WcfEventSource.Instance.MaxSessionSizeReachedIsEnabled())
                            {
                                WcfEventSource.Instance.MaxSessionSizeReached(message);
                            }
                            Exception inner = new QuotaExceededException(message);
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(message, inner));
                        }
                        else
                        {
                            _remainingReaderSessionSize -= dictionarySize;
                        }

                        int size = dictionarySize;
                        int offset = messageData.Offset + headerSize;

                        while (size > 0)
                        {
                            decoder.Reset();
                            int bytesDecoded = decoder.Decode(buffer, offset, size);
                            int utf8ValueSize = decoder.Value;
                            offset += bytesDecoded;
                            size -= bytesDecoded;
                            if (utf8ValueSize > size)
                            {
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(SR.BinaryEncoderSessionMalformed));
                            }
                            string value = Encoding.UTF8.GetString(buffer, offset, utf8ValueSize);
                            offset += utf8ValueSize;
                            size -= utf8ValueSize;
                            _readerSession.Add(_idCounter, value);
                            _idCounter++;
                        }
                    }
                    throwing = false;
                }
                finally
                {
                    if (throwing)
                    {
                        _isReaderSessionInvalid = true;
                    }
                }

                return new ArraySegment<byte>(buffer, newOffset, newSize);
            }
Beispiel #9
0
 public SingletonMessageDecoder(long streamPosition)
     : base(streamPosition)
 {
     this.sizeDecoder = new IntDecoder();
     this.currentState = State.ChunkStart;
 }
Beispiel #10
0
 public ServerSessionDecoder(long streamPosition, int maxViaLength, int maxContentTypeLength)
     : base(streamPosition)
 {
     this.viaDecoder = new ViaStringDecoder(maxViaLength);
     this.contentTypeDecoder = new ContentTypeStringDecoder(maxContentTypeLength);
     this.sizeDecoder = new IntDecoder();
     this.currentState = State.ReadingViaRecord;
 }
Beispiel #11
0
 public ClientDuplexDecoder(long streamPosition)
     : base(streamPosition)
 {
     sizeDecoder = new IntDecoder();
 }
 public StringDecoder(int sizeQuota)
 {
     _sizeQuota = sizeQuota;
     _sizeDecoder = new IntDecoder();
     _currentState = State.ReadingSize;
     Reset();
 }
 private ArraySegment<byte> ExtractSessionInformationFromMessage(ArraySegment<byte> messageData)
 {
     int num3;
     int num4;
     if (this.isReaderSessionInvalid)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(System.ServiceModel.SR.GetString("BinaryEncoderSessionInvalid")));
     }
     byte[] array = messageData.Array;
     bool flag = true;
     try
     {
         IntDecoder decoder = new IntDecoder();
         int num2 = decoder.Decode(array, messageData.Offset, messageData.Count);
         int num = decoder.Value;
         if (num > messageData.Count)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(System.ServiceModel.SR.GetString("BinaryEncoderSessionMalformed")));
         }
         num3 = (messageData.Offset + num2) + num;
         num4 = (messageData.Count - num2) - num;
         if (num4 < 0)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(System.ServiceModel.SR.GetString("BinaryEncoderSessionMalformed")));
         }
         if (num > 0)
         {
             if (num > this.remainingReaderSessionSize)
             {
                 string message = System.ServiceModel.SR.GetString("BinaryEncoderSessionTooLarge", new object[] { this.maxSessionSize });
                 Exception innerException = new QuotaExceededException(message);
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(message, innerException));
             }
             this.remainingReaderSessionSize -= num;
             int size = num;
             int offset = messageData.Offset + num2;
             while (size > 0)
             {
                 decoder.Reset();
                 int num7 = decoder.Decode(array, offset, size);
                 int count = decoder.Value;
                 offset += num7;
                 size -= num7;
                 if (count > size)
                 {
                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(System.ServiceModel.SR.GetString("BinaryEncoderSessionMalformed")));
                 }
                 string str2 = Encoding.UTF8.GetString(array, offset, count);
                 offset += count;
                 size -= count;
                 this.readerSession.Add(this.idCounter, str2);
                 this.idCounter++;
             }
         }
         flag = false;
     }
     finally
     {
         if (flag)
         {
             this.isReaderSessionInvalid = true;
         }
     }
     return new ArraySegment<byte>(array, num3, num4);
 }