Skip to content

Commit bde3202

Browse files
author
Vincent Van Mulders
committed
Allow sizeLimit to be passed to mergeFromBuffer so it can be passed to CodedBufferReader to override the 64MB size limit
1 parent f085bfd commit bde3202

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

protobuf/lib/src/protobuf/coded_buffer_reader.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ class CodedBufferReader {
2626
final int _sizeLimit;
2727

2828
CodedBufferReader(List<int> buffer,
29-
{int recursionLimit = DEFAULT_RECURSION_LIMIT,
30-
int sizeLimit = DEFAULT_SIZE_LIMIT})
29+
{int recursionLimit = DEFAULT_RECURSION_LIMIT, int? sizeLimit})
3130
: _buffer = buffer is Uint8List ? buffer : Uint8List.fromList(buffer),
3231
_recursionLimit = recursionLimit,
33-
_sizeLimit = math.min(sizeLimit, buffer.length) {
32+
_sizeLimit = math.min(sizeLimit ?? DEFAULT_SIZE_LIMIT, buffer.length) {
3433
_currentLimit = _sizeLimit;
3534
}
3635

protobuf/lib/src/protobuf/generated_message.dart

+6-3
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,12 @@ abstract class GeneratedMessage {
198198
/// * Else, if it's a scalar, this overwrites our field.
199199
/// * Else, (it's a non-repeated sub-message), this recursively merges into
200200
/// the existing sub-message.
201-
void mergeFromBuffer(List<int> input,
202-
[ExtensionRegistry extensionRegistry = ExtensionRegistry.EMPTY]) {
203-
final codedInput = CodedBufferReader(input);
201+
void mergeFromBuffer(
202+
List<int> input, [
203+
ExtensionRegistry extensionRegistry = ExtensionRegistry.EMPTY,
204+
int? sizeLimit,
205+
]) {
206+
final codedInput = CodedBufferReader(input, sizeLimit: sizeLimit);
204207
final meta = _fieldSet._meta;
205208
_mergeFromCodedBufferReader(meta, _fieldSet, codedInput, extensionRegistry);
206209
codedInput.checkLastTagWas(0);

0 commit comments

Comments
 (0)