InvalidProtocolBufferException.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.IO;
  3. namespace Google.ProtocolBuffers {
  4. /// <summary>
  5. /// Thrown when a protocol message being parsed is invalid in some way,
  6. /// e.g. it contains a malformed varint or a negative byte length.
  7. ///
  8. /// TODO(jonskeet): Make the methods throw directly? Rename them?
  9. /// </summary>
  10. public class InvalidProtocolBufferException : IOException {
  11. private InvalidProtocolBufferException(string message)
  12. : base(message) {
  13. }
  14. internal static InvalidProtocolBufferException TruncatedMessage() {
  15. return new InvalidProtocolBufferException(
  16. "While parsing a protocol message, the input ended unexpectedly " +
  17. "in the middle of a field. This could mean either than the " +
  18. "input has been truncated or that an embedded message " +
  19. "misreported its own length.");
  20. }
  21. internal static InvalidProtocolBufferException NegativeSize() {
  22. return new InvalidProtocolBufferException(
  23. "CodedInputStream encountered an embedded string or message " +
  24. "which claimed to have negative size.");
  25. }
  26. internal static InvalidProtocolBufferException MalformedVarint() {
  27. return new InvalidProtocolBufferException(
  28. "CodedInputStream encountered a malformed varint.");
  29. }
  30. internal static InvalidProtocolBufferException InvalidTag() {
  31. return new InvalidProtocolBufferException(
  32. "Protocol message contained an invalid tag (zero).");
  33. }
  34. internal static InvalidProtocolBufferException InvalidEndTag() {
  35. return new InvalidProtocolBufferException(
  36. "Protocol message end-group tag did not match expected tag.");
  37. }
  38. internal static InvalidProtocolBufferException InvalidWireType() {
  39. return new InvalidProtocolBufferException(
  40. "Protocol message tag had invalid wire type.");
  41. }
  42. internal static InvalidProtocolBufferException RecursionLimitExceeded() {
  43. return new InvalidProtocolBufferException(
  44. "Protocol message had too many levels of nesting. May be malicious. " +
  45. "Use CodedInputStream.setRecursionLimit() to increase the depth limit.");
  46. }
  47. internal static InvalidProtocolBufferException SizeLimitExceeded() {
  48. return new InvalidProtocolBufferException(
  49. "Protocol message was too large. May be malicious. " +
  50. "Use CodedInputStream.setSizeLimit() to increase the size limit.");
  51. }
  52. }
  53. }