Skip to content

Commit

Permalink
Merge pull request #5613 from filecoin-project/feat/client-commp-car
Browse files Browse the repository at this point in the history
Check format in client commP util
  • Loading branch information
magik6k authored Feb 16, 2021
2 parents ea7ea72 + 39ad3d3 commit b6c75d6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions node/impl/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,16 @@ func (a *API) ClientCalcCommP(ctx context.Context, inpath string) (*api.CommPRet
return nil, err
}

// check that the data is a car file; if it's not, retrieval won't work
_, _, err = car.ReadHeader(bufio.NewReader(rdr))
if err != nil {
return nil, xerrors.Errorf("not a car file: %w", err)
}

if _, err := rdr.Seek(0, io.SeekStart); err != nil {
return nil, xerrors.Errorf("seek to start: %w", err)
}

pieceReader, pieceSize := padreader.New(rdr, uint64(stat.Size()))
commP, err := ffiwrapper.GeneratePieceCIDFromFile(arbitraryProofType, pieceReader, pieceSize)

Expand Down

0 comments on commit b6c75d6

Please sign in to comment.