• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #region Copyright notice and license
2 // Protocol Buffers - Google's data interchange format
3 // Copyright 2008 Google Inc.  All rights reserved.
4 //
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file or at
7 // https://developers.google.com/open-source/licenses/bsd
8 #endregion
9 
10 using System;
11 using System.IO;
12 
13 namespace Google.Protobuf
14 {
15     /// <summary>
16     /// Thrown when a protocol message being parsed is invalid in some way,
17     /// e.g. it contains a malformed varint or a negative byte length.
18     /// </summary>
19     public sealed class InvalidProtocolBufferException : IOException
20     {
InvalidProtocolBufferException(string message)21         internal InvalidProtocolBufferException(string message)
22             : base(message)
23         {
24         }
25 
InvalidProtocolBufferException(string message, Exception innerException)26         internal InvalidProtocolBufferException(string message, Exception innerException)
27             : base(message, innerException)
28         {
29         }
30 
MoreDataAvailable()31         internal static InvalidProtocolBufferException MoreDataAvailable()
32         {
33             return new InvalidProtocolBufferException(
34                 "Completed reading a message while more data was available in the stream.");
35         }
36 
TruncatedMessage()37         internal static InvalidProtocolBufferException TruncatedMessage()
38         {
39             return new InvalidProtocolBufferException(
40                 "While parsing a protocol message, the input ended unexpectedly " +
41                 "in the middle of a field.  This could mean either that the " +
42                 "input has been truncated or that an embedded message " +
43                 "misreported its own length.");
44         }
45 
NegativeSize()46         internal static InvalidProtocolBufferException NegativeSize()
47         {
48             return new InvalidProtocolBufferException(
49                 "CodedInputStream encountered an embedded string or message " +
50                 "which claimed to have negative size.");
51         }
52 
MalformedVarint()53         internal static InvalidProtocolBufferException MalformedVarint()
54         {
55             return new InvalidProtocolBufferException(
56                 "CodedInputStream encountered a malformed varint.");
57         }
58 
59         /// <summary>
60         /// Creates an exception for an error condition of an invalid tag being encountered.
61         /// </summary>
InvalidTag()62         internal static InvalidProtocolBufferException InvalidTag()
63         {
64             return new InvalidProtocolBufferException(
65                 "Protocol message contained an invalid tag (zero).");
66         }
67 
InvalidWireType()68         internal static InvalidProtocolBufferException InvalidWireType()
69         {
70             return new InvalidProtocolBufferException(
71                 "Protocol message contained a tag with an invalid wire type.");
72         }
73 
InvalidBase64(Exception innerException)74         internal static InvalidProtocolBufferException InvalidBase64(Exception innerException)
75         {
76             return new InvalidProtocolBufferException("Invalid base64 data", innerException);
77         }
78 
InvalidEndTag()79         internal static InvalidProtocolBufferException InvalidEndTag()
80         {
81             return new InvalidProtocolBufferException(
82                 "Protocol message end-group tag did not match expected tag.");
83         }
84 
RecursionLimitExceeded()85         internal static InvalidProtocolBufferException RecursionLimitExceeded()
86         {
87             return new InvalidProtocolBufferException(
88                 "Protocol message had too many levels of nesting.  May be malicious.  " +
89                 "Use CodedInputStream.SetRecursionLimit() to increase the depth limit.");
90         }
91 
JsonRecursionLimitExceeded()92         internal static InvalidProtocolBufferException JsonRecursionLimitExceeded()
93         {
94             return new InvalidProtocolBufferException(
95                 "Protocol message had too many levels of nesting.  May be malicious.  " +
96                 "Use JsonParser.Settings to increase the depth limit.");
97         }
98 
SizeLimitExceeded()99         internal static InvalidProtocolBufferException SizeLimitExceeded()
100         {
101             return new InvalidProtocolBufferException(
102                 "Protocol message was too large.  May be malicious.  " +
103                 "Use CodedInputStream.SetSizeLimit() to increase the size limit.");
104         }
105 
InvalidMessageStreamTag()106         internal static InvalidProtocolBufferException InvalidMessageStreamTag()
107         {
108             return new InvalidProtocolBufferException(
109                 "Stream of protocol messages had invalid tag. Expected tag is length-delimited field 1.");
110         }
111 
MissingFields()112         internal static InvalidProtocolBufferException MissingFields()
113         {
114             return new InvalidProtocolBufferException("Message was missing required fields");
115         }
116     }
117 }