diff --git a/plugin/plugins/git/git.go b/plugin/plugins/git/git.go index 5ec5d6f16..aa3f57297 100644 --- a/plugin/plugins/git/git.go +++ b/plugin/plugins/git/git.go @@ -2,12 +2,15 @@ package git import ( "compress/zlib" + "fmt" "io" + "math" "github.com/ipfs/go-ipfs/core/coredag" "github.com/ipfs/go-ipfs/plugin" "gx/ipfs/QmTprEaAA2A9bst5XH7exuyi5KzNMK3SEDNN8rBDnKWcUS/go-cid" + mh "gx/ipfs/QmU9a9NV9RdPNwZQDYd5uKsm6N6LJLSvLbywDDYFbaaC6P/go-multihash" "gx/ipfs/QmYNyRZJBUYPNrLszFmrBrPJbsBh2vMsefz5gnDpB5M1P6/go-ipld-format" git "gx/ipfs/Qma7Kuwun7w8SZphjEPDVxvGfetBkqdNGmigDA13sJdLex/go-ipld-git" ) @@ -44,7 +47,15 @@ func (*gitPlugin) RegisterInputEncParsers(iec coredag.InputEncParsers) error { return nil } -func parseRawGit(r io.Reader) ([]format.Node, error) { +func parseRawGit(r io.Reader, mhType uint64, mhLen int) ([]format.Node, error) { + if mhType != math.MaxUint64 && mhType != mh.SHA1 { + return nil, fmt.Errorf("unsupported mhType %d", mhType) + } + + if mhLen != -1 && mhLen != mh.DefaultLengths[mh.SHA1] { + return nil, fmt.Errorf("invalid mhLen %d", mhType) + } + nd, err := git.ParseObject(r) if err != nil { return nil, err @@ -53,12 +64,12 @@ func parseRawGit(r io.Reader) ([]format.Node, error) { return []format.Node{nd}, nil } -func parseZlibGit(r io.Reader) ([]format.Node, error) { +func parseZlibGit(r io.Reader, mhType uint64, mhLen int) ([]format.Node, error) { rc, err := zlib.NewReader(r) if err != nil { return nil, err } defer rc.Close() - return parseRawGit(rc) + return parseRawGit(rc, mhType, mhLen) }