-
Notifications
You must be signed in to change notification settings - Fork 38
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
feat: improve broken cid.Builder testing for CidBuilder #93
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to the changes suggested to checking Sum
, should we also sanity check values returned by GetCodec
and WithCodec
? Is there a fixed set of codecs/behaviours we expect the builder to provide when those two functions are called?
If so, let's assert those too while at it.
node.go
Outdated
} else { | ||
// have to test it's a usable hasher directly | ||
// this is only a basic check, there are still ways it may break | ||
_, err := builder.Sum([]byte{0}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to @Jorropo's suggestion on using an array here.
Thinking out loud I also wonder if we can do better:
Disclaimer: I am not fully familiar with how this API is used.
We could get the digest value back, read the multihash code from the beginning and call checkHasher
function from my earlier suggestion to see if the multi hash code fits?
064ec5a
to
d910fbc
Compare
@Jorropo @masih see second-to-latest commit incorporating feedback (d910fbc). The latest commit is not essential and I'd really like feedback on this one before we go ahead with it—I've entirely removed the Some more discussion on With that in mind, we could go ahead and check the output of a There's an additional problem here that this is set for each instance of a My opinion on this is something like—there's a place here where you could provide a bad |
node.go
Outdated
func (n *ProtoNode) RawData() []byte { | ||
out, err := n.EncodeProtobuf(false) | ||
if err != nil { | ||
panic(err) | ||
return []byte{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
nil
slice length is0
I think returning nil is practically the same as returning an empty slice. -
If this project already depends on
ipfs/go-log
maybe log the error since we can't return it?
return []byte{} | |
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no it doesn't depend on go-log directly which is why I didn't do that here, but there's a few indirect uses of it and considering where this library will be used it's probably not going to be a big deal to include it; I've added some log entries for it, feels a bit better.
the latest commit to avoid potential for panics seems okay -
|
we're dealing with legacy go-ipld-format etc. interfaces here so it's not going to be practical to introduce new APIs to that and work through all the uses of it, especially since we are trying to deprecate these! the I've added log messages and returned |
If you don't use something derived from a cid.Prefix then it'll test execute your hasher to make sure it doesn't error. The reason for this is to avoid more cases where a panic could occur when encoding a ProtoNode. fix: apply code-review feedback Co-authored-by: Masih H. Derkani <m@derkani.org>
e00a51a
to
af63637
Compare
Suggested version: Changes in diff --git a/go.mod b/go.mod
index 197ce60..2f8ca57 100644
--- a/go.mod
+++ b/go.mod
@@ -12,6 +12,7 @@ require (
github.com/ipfs/go-ipld-cbor v0.0.5
github.com/ipfs/go-ipld-format v0.3.0
github.com/ipfs/go-ipld-legacy v0.1.0
+ github.com/ipfs/go-log/v2 v2.5.1
github.com/ipld/go-codec-dagpb v1.3.1
github.com/ipld/go-ipld-prime v0.16.0
github.com/multiformats/go-multihash v0.2.1
@@ -33,7 +34,6 @@ require (
github.com/ipfs/go-ipfs-pq v0.0.2 // indirect
github.com/ipfs/go-ipfs-routing v0.2.1 // indirect
github.com/ipfs/go-log v1.0.5 // indirect
- github.com/ipfs/go-log/v2 v2.3.0 // indirect
github.com/ipfs/go-metrics-interface v0.0.1 // indirect
github.com/ipfs/go-peertaskqueue v0.7.0 // indirect
github.com/ipfs/go-verifcid v0.0.1 // indirect
@@ -58,7 +58,7 @@ require (
github.com/libp2p/go-netroute v0.1.6 // indirect
github.com/libp2p/go-openssl v0.0.7 // indirect
github.com/libp2p/go-sockaddr v0.1.1 // indirect
- github.com/mattn/go-isatty v0.0.13 // indirect
+ github.com/mattn/go-isatty v0.0.14 // indirect
github.com/miekg/dns v1.1.41 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
@@ -78,10 +78,10 @@ require (
github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
- go.uber.org/zap v1.16.0 // indirect
+ go.uber.org/zap v1.19.1 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
- golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
+ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/grpc v1.33.2 // indirect
|
If you don't use something derived from a cid.Prefix then it'll test execute your hasher to make sure it doesn't error.
The reason for this is to avoid more cases where a panic could occur when encoding a ProtoNode.