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

Remove proto size restriction when parsing protos. #836

Closed
wants to merge 4 commits into from

Conversation

nmittler
Copy link
Member

@ejona86 PTAL .. this is the first part of the change to support maxMessageSize.

CodedInputStream codedInput = CodedInputStream.newInstance(stream);
codedInput.setSizeLimit(Integer.MAX_VALUE);

return parser.parseFrom(codedInput);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the documentation for parseFrom(CodedInputStream):

Note: The caller should call CodedInputStream#checkLastTagWas(int) after calling this to verify that the last tag seen was the appropriate end-group tag, or zero for EOF.

In my comment in #832, I say:

The only gotcha I see is that we need to call checkLastTagWas(0) afterward.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch ... missed that. Done!

@nmittler
Copy link
Member Author

@ejona86 PTAL

@ejona86
Copy link
Member

ejona86 commented Aug 20, 2015

Do we want to do the same thing that proto does if the message was incomplete?

    try {
      codedInput.checkLastTagWas(0);
    } catch (InvalidProtocolBufferException e) {
      throw e.setUnfinishedMessage(message);
    }

That does actually look useful, as you can piece together what the message was a bit, but aren't accidentally going to trust it. That does seem useful for debugging.

// when parsing.
CodedInputStream codedInput = CodedInputStream.newInstance(stream);
codedInput.setSizeLimit(Integer.MAX_VALUE);
codedInput.checkLastTagWas(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to happen after parseFrom() to have any purpose.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@nmittler
Copy link
Member Author

@ejona86 PTAL

@ejona86
Copy link
Member

ejona86 commented Aug 20, 2015

@nmittler LGTM

@nmittler
Copy link
Member Author

Cherry-picked as 573f79a

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

Successfully merging this pull request may close these issues.

3 participants