Skip to content

Commit

Permalink
Allow sizeLimit to be passed to mergeFromBuffer so it can be passed t…
Browse files Browse the repository at this point in the history
…o CodedBufferReader to override the 64MB size limit
  • Loading branch information
vvanm committed Feb 23, 2024
1 parent f085bfd commit 8f6828a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 2 additions & 3 deletions protobuf/lib/src/protobuf/coded_buffer_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ class CodedBufferReader {
final int _sizeLimit;

CodedBufferReader(List<int> 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;
}

Expand Down
9 changes: 6 additions & 3 deletions protobuf/lib/src/protobuf/generated_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> input,
[ExtensionRegistry extensionRegistry = ExtensionRegistry.EMPTY]) {
final codedInput = CodedBufferReader(input);
void mergeFromBuffer(
List<int> 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);
Expand Down
7 changes: 5 additions & 2 deletions protobuf/lib/src/protobuf/message_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,11 @@ abstract class $_MessageSet extends GeneratedMessage {
}

@override
void mergeFromBuffer(List<int> input,
[ExtensionRegistry extensionRegistry = ExtensionRegistry.EMPTY]) {
void mergeFromBuffer(
List<int> input, [
ExtensionRegistry extensionRegistry = ExtensionRegistry.EMPTY,
int? sizeLimit,
]) {
mergeFromCodedBufferReader(CodedBufferReader(input), extensionRegistry);
}

Expand Down

0 comments on commit 8f6828a

Please sign in to comment.