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

Add test script for car verify #236

Merged
merged 4 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/car/testdata/script/verify.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# "verify" should exit with code 0 on reasonable cars.
car verify ${INPUTS}/sample-v1.car
car verify ${INPUTS}/sample-wrapped-v2.car
15 changes: 13 additions & 2 deletions cmd/car/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ipfs/go-cid"
carv2 "github.com/ipld/go-car/v2"
"github.com/ipld/go-car/v2/index"
"github.com/multiformats/go-multihash"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -44,12 +45,15 @@ func VerifyCar(c *cli.Context) error {
if err != nil {
return err
}
lengthToIndex := carv2.PragmaSize + carv2.HeaderSize + rx.Header.DataOffset + rx.Header.DataSize
lengthToIndex := carv2.PragmaSize + carv2.HeaderSize + rx.Header.DataSize
if uint64(flen.Size()) > lengthToIndex && rx.Header.IndexOffset == 0 {
return fmt.Errorf("header claims no index, but extra bytes in file beyond data size")
}
if rx.Header.DataOffset < carv2.PragmaSize+carv2.HeaderSize {
return fmt.Errorf("data offset places data within carv2 header")
}
if rx.Header.IndexOffset < lengthToIndex {
return fmt.Errorf("index offset overlaps with data")
return fmt.Errorf("index offset overlaps with data. data ends at %d. index offset of %d", lengthToIndex, rx.Header.IndexOffset)
}
}

Expand Down Expand Up @@ -87,6 +91,13 @@ func VerifyCar(c *cli.Context) error {
return err
}
for _, c := range cidList {
cidHash, err := multihash.Decode(c.Hash())
if err != nil {
return err
}
if cidHash.Code == multihash.IDENTITY {
continue
}
if err := idx.GetAll(c, func(_ uint64) bool {
return true
}); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ require (
github.com/ipfs/go-cid v0.1.0
github.com/ipfs/go-ipfs-blockstore v1.0.3
github.com/ipld/go-car v0.3.1
github.com/ipld/go-car/v2 v2.0.2
github.com/ipld/go-car/v2 v2.0.3-0.20210914083849-7544041c42bb
github.com/ipld/go-codec-dagpb v1.2.0
github.com/ipld/go-ipld-prime v0.12.3-0.20210910135350-e6597215c6d5
github.com/multiformats/go-multicodec v0.3.1-0.20210902112759-1539a079fd61
github.com/multiformats/go-multihash v0.0.15
github.com/multiformats/go-varint v0.0.6
github.com/rogpeppe/go-internal v1.8.0
github.com/urfave/cli/v2 v2.3.0
Expand Down
5 changes: 2 additions & 3 deletions cmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ github.com/ipfs/go-verifcid v0.0.1 h1:m2HI7zIuR5TFyQ1b79Da5N9dnnCP1vcu2QqawmWlK2
github.com/ipfs/go-verifcid v0.0.1/go.mod h1:5Hrva5KBeIog4A+UpqlaIU+DEstipcJYQQZc0g37pY0=
github.com/ipld/go-car v0.3.1 h1:WT+3cdmXlvmWOlGxk9webhj4auGO5QvgqC2vCCkFRXs=
github.com/ipld/go-car v0.3.1/go.mod h1:dPkEWeAK8KaVvH5TahaCs6Mncpd4lDMpkbs0/SPzuVs=
github.com/ipld/go-car/v2 v2.0.2 h1:R1oIAPwrGp26mEFzcGf5bfTZAAHDOkaVnZTEVebaWX4=
github.com/ipld/go-car/v2 v2.0.2/go.mod h1:I2ACeeg6XNBe5pdh5TaR7Ambhfa7If9KXxmXgZsYENU=
github.com/ipld/go-car/v2 v2.0.3-0.20210914083849-7544041c42bb h1:w86j9nGrl+kCsrWF2KAevmqnkT7gMWjr4uSZ/a5jwWY=
github.com/ipld/go-car/v2 v2.0.3-0.20210914083849-7544041c42bb/go.mod h1:Xr6GwkDhv8dtOtgHzOynAkIOg0t0YiPc5DxBPppWqZA=
github.com/ipld/go-codec-dagpb v1.2.0 h1:2umV7ud8HBMkRuJgd8gXw95cLhwmcYrihS3cQEy9zpI=
github.com/ipld/go-codec-dagpb v1.2.0/go.mod h1:6nBN7X7h8EOsEejZGqC7tej5drsdBAXbMHyBT+Fne5s=
github.com/ipld/go-ipld-prime v0.9.0/go.mod h1:KvBLMr4PX1gWptgkzRjVZCrLmSGcZCb/jioOQwCqZN8=
Expand Down Expand Up @@ -391,7 +391,6 @@ github.com/multiformats/go-multiaddr-net v0.0.1/go.mod h1:nw6HSxNmCIQH27XPGBuX+d
github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs=
github.com/multiformats/go-multibase v0.0.3 h1:l/B6bJDQjvQ5G52jw4QGSYeOTZoAwIO77RblWplfIqk=
github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc=
github.com/multiformats/go-multicodec v0.2.1-0.20210713081508-b421db6850ae/go.mod h1:qGGaQmioCDh+TeFOnxrbU0DaIPw8yFgAZgFG0V7p1qQ=
github.com/multiformats/go-multicodec v0.3.0/go.mod h1:qGGaQmioCDh+TeFOnxrbU0DaIPw8yFgAZgFG0V7p1qQ=
github.com/multiformats/go-multicodec v0.3.1-0.20210902112759-1539a079fd61 h1:ZrUuMKNgJ52qHPoQ+bx0h0uBfcWmN7Px+4uKSZeesiI=
github.com/multiformats/go-multicodec v0.3.1-0.20210902112759-1539a079fd61/go.mod h1:1Hj/eHRaVWSXiSNNfcEPcwZleTmdNP81xlxDLnWU9GQ=
Expand Down