-
Notifications
You must be signed in to change notification settings - Fork 22
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
start rejecting Metadata.ProtocolID == 0 #94
Comments
Moved the issue to storetheindex, as I see @gammazero moved the type here. I'll send the first PR here shortly. |
mvdan
added a commit
that referenced
this issue
Oct 13, 2021
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.
PR up at #95. I'll keep this issue open until the changes are propagated. Presumably, only indexer-reference-provider needs to be updated. |
mvdan
added a commit
that referenced
this issue
Oct 13, 2021
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.
mvdan
added a commit
that referenced
this issue
Oct 13, 2021
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the user forgets to set it, we should catch that as an error instead of silently assuming whatever id==0 happens to be. I imagine it will be an easy mistake to make, and could lead to very confusing errors down the line, e.g. metadata decode errors on the other side.
For instance, one can't make Go struct types exhaustive, so it can be easy to just type
indexer.Metadata{Data: someData}
and not set the protocol ID at all.The text was updated successfully, but these errors were encountered: