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

api/v0: reject Metadata.ProtocolID == 0 #95

Merged
merged 1 commit into from
Oct 13, 2021
Merged

Conversation

mvdan
Copy link
Contributor

@mvdan mvdan commented Oct 13, 2021

(see commit message)

server/admin/http/handler.go Outdated Show resolved Hide resolved
@mvdan
Copy link
Contributor Author

mvdan commented Oct 13, 2021

Why is Circle running and just erroring immediately?

@willscott
Copy link
Member

Why is Circle running and just erroring immediately?

Because nobody has pushed #87 over the finish line

Integers in Go default to the zero value, meaning that if the user
forgets to set the protocol ID, it could transparently default to a
confusing value. For instance:

	metadata := v0.Metadata{Data: someData}

This could lead to confusing decode errors later on, or to metadata
being mistaken for the wrong kind.

Instead, reject this zero value. The protocol ID is a multihash anyway,
and we want users to either select registered indexer metadata
multihashes, or a multihash in the reserved range for testing.

The check happens at both encode and decode, for extra safety.
This required adding an error return on the encode side.
While we're there, make Metadata implement encoding's Binary interfaces.

Updates #94.
Copy link
Collaborator

@gammazero gammazero left a comment

Choose a reason for hiding this comment

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

LGTM.

// EncodeMetadata serializes Metadata to []byte.
func (m Metadata) Encode() []byte {
// MarshalBinary implements encoding.BinaryMarshaler.
func (m Metadata) MarshalBinary() ([]byte, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

🎉

@mvdan mvdan merged commit 9f160c0 into main Oct 13, 2021
@mvdan mvdan deleted the metadata-encoding-error branch October 13, 2021 18:50
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.

3 participants