From 8f6828af4b4f834a6c8c03fcf2ebf5f32f8b2ad4 Mon Sep 17 00:00:00 2001 From: vvanm Date: Fri, 23 Feb 2024 08:45:56 +0100 Subject: [PATCH] Allow sizeLimit to be passed to mergeFromBuffer so it can be passed to CodedBufferReader to override the 64MB size limit --- protobuf/lib/src/protobuf/coded_buffer_reader.dart | 5 ++--- protobuf/lib/src/protobuf/generated_message.dart | 9 ++++++--- protobuf/lib/src/protobuf/message_set.dart | 7 +++++-- 3 files changed, 13 insertions(+), 8 deletions(-) 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); diff --git a/protobuf/lib/src/protobuf/message_set.dart b/protobuf/lib/src/protobuf/message_set.dart index ba9664d64..396e643ae 100644 --- a/protobuf/lib/src/protobuf/message_set.dart +++ b/protobuf/lib/src/protobuf/message_set.dart @@ -115,8 +115,11 @@ abstract class $_MessageSet extends GeneratedMessage { } @override - void mergeFromBuffer(List input, - [ExtensionRegistry extensionRegistry = ExtensionRegistry.EMPTY]) { + void mergeFromBuffer( + List input, [ + ExtensionRegistry extensionRegistry = ExtensionRegistry.EMPTY, + int? sizeLimit, + ]) { mergeFromCodedBufferReader(CodedBufferReader(input), extensionRegistry); }