Skip to content

deterministic marshaling for non regenerated code #648

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

Closed
awalterschulze opened this issue Jun 29, 2018 · 7 comments
Closed

deterministic marshaling for non regenerated code #648

awalterschulze opened this issue Jun 29, 2018 · 7 comments

Comments

@awalterschulze
Copy link

It seems that the Marshal method is called when deterministic is true or false.
https://github.com/golang/protobuf/blob/master/proto/table_marshal.go#L227-L232

This might be a non deterministic generated Marshal method in a library used by a user pulling in the newer version of golang/protobuf, where they are able to set deterministic to true.

Even if we modify this code to rather be

if u.hasmarshaler && !deterministic {
		...
}

We also have to worry about
https://github.com/golang/protobuf/blob/master/proto/table_marshal.go#L310-L314
Which means that if there is a Marshaler the size cache is not set, but the non generated marshal function assumes that it is set.

How do we solve this?

@dsnet
Copy link
Member

dsnet commented Jun 30, 2018

The unfortunate reality is that we can't reconcile this issue in the present API. If deterministic marshaling is enabled, it will just have to be a best effort as it is impossible to know whether custom implementations are deterministic or not.

The design of the protoiface API is intended to enable to safer way for custom implementations to coexist.

@awalterschulze
Copy link
Author

Wouldn't it be more appropriate to tell the user that they are not getting the output by returning an error.

if u.hasmarshaler {
                if deterministic {
                        return nil, fmt.Errorf("deterministic not supported by the Marshal method of %v", u.typ)
                }
		m := ptr.asPointerTo(u.typ).Interface().(Marshaler)
		b1, err := m.Marshal()
		b = append(b, b1...)
		return b, err
}

@awalterschulze
Copy link
Author

@dsnet ^^ ?

@dsnet
Copy link
Member

dsnet commented Jul 9, 2018

Strict erroring for custom unmarshalers sounds good to me. Would you like to submit a PR?

@awalterschulze
Copy link
Author

That is great to hear :)

Just checking you mean marshalers and not unmarshalers, right?

@dsnet
Copy link
Member

dsnet commented Jul 10, 2018

Correct.

@awalterschulze
Copy link
Author

@jmarais is working on a pull request.

Thank you so much :)

jmarais pushed a commit to jmarais/protobuf-1 that referenced this issue Jul 10, 2018
jmarais added a commit to jmarais/protobuf-1 that referenced this issue Jul 10, 2018
@dsnet dsnet closed this as completed Jul 12, 2018
@golang golang locked and limited conversation to collaborators Jun 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants