diff --git a/protobuf/lib/src/protobuf/coded_buffer_reader.dart b/protobuf/lib/src/protobuf/coded_buffer_reader.dart index cc7e3ddf1..5da7dae0a 100644 --- a/protobuf/lib/src/protobuf/coded_buffer_reader.dart +++ b/protobuf/lib/src/protobuf/coded_buffer_reader.dart @@ -26,11 +26,10 @@ class CodedBufferReader { final int _sizeLimit; CodedBufferReader(List buffer, - {int recursionLimit = DEFAULT_RECURSION_LIMIT, - int sizeLimit = DEFAULT_SIZE_LIMIT}) + {int recursionLimit = DEFAULT_RECURSION_LIMIT, int? sizeLimit}) : _buffer = buffer is Uint8List ? buffer : Uint8List.fromList(buffer), _recursionLimit = recursionLimit, - _sizeLimit = math.min(sizeLimit, buffer.length) { + _sizeLimit = math.min(sizeLimit ?? DEFAULT_SIZE_LIMIT, buffer.length) { _currentLimit = _sizeLimit; } diff --git a/protobuf/lib/src/protobuf/generated_message.dart b/protobuf/lib/src/protobuf/generated_message.dart index d34dac4ad..370d848d3 100644 --- a/protobuf/lib/src/protobuf/generated_message.dart +++ b/protobuf/lib/src/protobuf/generated_message.dart @@ -198,9 +198,12 @@ abstract class GeneratedMessage { /// * Else, if it's a scalar, this overwrites our field. /// * Else, (it's a non-repeated sub-message), this recursively merges into /// the existing sub-message. - void mergeFromBuffer(List input, - [ExtensionRegistry extensionRegistry = ExtensionRegistry.EMPTY]) { - final codedInput = CodedBufferReader(input); + void mergeFromBuffer( + List input, [ + ExtensionRegistry extensionRegistry = ExtensionRegistry.EMPTY, + int? sizeLimit, + ]) { + final codedInput = CodedBufferReader(input, sizeLimit: sizeLimit); final meta = _fieldSet._meta; _mergeFromCodedBufferReader(meta, _fieldSet, codedInput, extensionRegistry); codedInput.checkLastTagWas(0);