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

Conversation

vvanm
Copy link

@vvanm vvanm commented Feb 23, 2024

…o CodedBufferReader to override the 64MB size limit

We have cases in our flutter application where we need to parse files larger than 64MB.
Since there is a hard limit in CodedBuffferReader of 64MB we are running into issues there.

Since sizeLimit cannot be passed in from anywhere, this PR hopes to fix that so the sizeLimit is customizable from outside protobuf.

Copy link

google-cla bot commented Feb 23, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@vvanm vvanm force-pushed the generated_message_size_limit_parameter branch from bde3202 to 34c1b2c Compare February 23, 2024 07:54
@osa1
Copy link
Member

osa1 commented Feb 23, 2024

Since sizeLimit cannot be passed in from anywhere

Instead of

final msg = MyMessage.fromBuffer(data, registry);

you can do:

final reader = CodedBufferReader(data, sizeLimit: data.length);
final msg = MyMessage.create()..mergeFromCodedBufferReader(reader, registry);

…o CodedBufferReader to override the 64MB size limit
@vvanm vvanm force-pushed the generated_message_size_limit_parameter branch from 34c1b2c to 8f6828a Compare February 23, 2024 10:40
@vvanm
Copy link
Author

vvanm commented Feb 23, 2024

Hi,

I didn't notice that, thanks for the tip.

We using protoc like this:
protoc --proto_path=packages/metadata/proto --dart_out packages/metadata/lib packages/metadata/proto/root.proto packages/metadata/proto/metadata.proto packages/metadata/proto/protobuf-net/bcl.proto

Which generates code like

class Asset extends $pb.GeneratedMessage {
////

factory Asset.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);

////
}

Any tips on how to modify the generation so the reader is created and a limit can be set? Are there parameters on protoc command that can do this?

Thank you,
Vincent

@osa1
Copy link
Member

osa1 commented Feb 23, 2024

You can't modify the generated code, you need to use mergeFromCodedBufferReader with a CodedBufferReader with a custom limit, as shown above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants