From 39ad3d3b279509b04e54a3724dafba0341b044ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 16 Feb 2021 20:48:31 +0100 Subject: [PATCH] Check format in client commP util --- node/impl/client/client.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/node/impl/client/client.go b/node/impl/client/client.go index 00c840b6360..ac526ac6030 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -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)