aboutsummaryrefslogtreecommitdiff
path: root/src/ProtocolBuffers/Serialization/AbstractReader.cs
diff options
context:
space:
mode:
authorcsharptest <roger@csharptest.net>2011-06-11 12:22:17 -0500
committerrogerk <devnull@localhost>2011-06-11 12:22:17 -0500
commit3b70dd78ec6b3b348b51766ea728d8226c908fd6 (patch)
tree37660dd74701f61dbbff7fe23fd2b8b3679c654d /src/ProtocolBuffers/Serialization/AbstractReader.cs
parent57fa7fddd7255acf5169462ae08b71b4c73b6b18 (diff)
downloadprotobuf-3b70dd78ec6b3b348b51766ea728d8226c908fd6.tar.gz
protobuf-3b70dd78ec6b3b348b51766ea728d8226c908fd6.tar.bz2
protobuf-3b70dd78ec6b3b348b51766ea728d8226c908fd6.zip
Added recursion limits to AbstractReader.cs
Diffstat (limited to 'src/ProtocolBuffers/Serialization/AbstractReader.cs')
-rw-r--r--src/ProtocolBuffers/Serialization/AbstractReader.cs31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/ProtocolBuffers/Serialization/AbstractReader.cs b/src/ProtocolBuffers/Serialization/AbstractReader.cs
index 8e4030e6..eb9baae1 100644
--- a/src/ProtocolBuffers/Serialization/AbstractReader.cs
+++ b/src/ProtocolBuffers/Serialization/AbstractReader.cs
@@ -12,6 +12,9 @@ namespace Google.ProtocolBuffers.Serialization
/// </summary>
public abstract class AbstractReader : ICodedInputStream
{
+ const int MaxDepth = CodedInputStream.DefaultRecursionLimit;
+ protected int _depth;
+
/// <summary>
/// Merges the contents of stream into the provided message builder
/// </summary>
@@ -330,13 +333,23 @@ namespace Google.ProtocolBuffers.Serialization
{ return Read(ref value); }
void ICodedInputStream.ReadGroup(int fieldNumber, IBuilderLite builder, ExtensionRegistry extensionRegistry)
- { ReadGroup(builder, extensionRegistry); }
+ {
+ if (_depth++ > MaxDepth)
+ throw InvalidProtocolBufferException.RecursionLimitExceeded();
+ ReadGroup(builder, extensionRegistry);
+ _depth--;
+ }
void ICodedInputStream.ReadUnknownGroup(int fieldNumber, IBuilderLite builder)
{ throw new NotSupportedException(); }
void ICodedInputStream.ReadMessage(IBuilderLite builder, ExtensionRegistry extensionRegistry)
- { ReadMessage(builder, extensionRegistry); }
+ {
+ if (_depth++ > MaxDepth)
+ throw InvalidProtocolBufferException.RecursionLimitExceeded();
+ ReadMessage(builder, extensionRegistry);
+ _depth--;
+ }
bool ICodedInputStream.ReadBytes(ref ByteString value)
{ return Read(ref value); }
@@ -439,10 +452,20 @@ namespace Google.ProtocolBuffers.Serialization
}
void ICodedInputStream.ReadMessageArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType, ExtensionRegistry registry)
- { ReadMessageArray(fieldName, list, messageType, registry); }
+ {
+ if (_depth++ > MaxDepth)
+ throw InvalidProtocolBufferException.RecursionLimitExceeded();
+ ReadMessageArray(fieldName, list, messageType, registry);
+ _depth--;
+ }
void ICodedInputStream.ReadGroupArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType, ExtensionRegistry registry)
- { ReadGroupArray(fieldName, list, messageType, registry); }
+ {
+ if (_depth++ > MaxDepth)
+ throw InvalidProtocolBufferException.RecursionLimitExceeded();
+ ReadGroupArray(fieldName, list, messageType, registry);
+ _depth--;
+ }
bool ICodedInputStream.ReadPrimitiveField(FieldType fieldType, ref object value)
{ return ReadField(fieldType, ref value); }