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
Vincent Van Mulders committed Feb 23, 2024
1 parent f085bfd commit bde3202
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 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

0 comments on commit bde3202

Please sign in to comment.