Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sizeLimit to be passed to mergeFromBuffer so it can be passed t… #913

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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