11package nonffi
22
33import (
4+ "errors"
45 "fmt"
56 "math/bits"
67
@@ -16,18 +17,18 @@ func GenerateUnsealedCID(proofType abi.RegisteredSealProof, pieces []abi.PieceIn
1617 if ! found {
1718 return cid .Undef , fmt .Errorf ("unknown seal proof type %d" , proofType )
1819 }
19-
20- target := abi .PaddedPieceSize (spi .SectorSize )
2120 if len (pieces ) == 0 {
22- return zerocomm . ZeroPieceCommitment ( target . Unpadded ()), nil
21+ return cid . Undef , errors . New ( "no pieces provided" )
2322 }
2423
24+ maxSize := abi .PaddedPieceSize (spi .SectorSize )
25+
2526 // sancheck everything
2627 for i , p := range pieces {
2728 if p .Size < 128 {
2829 return cid .Undef , fmt .Errorf ("invalid Size of PieceInfo %d: value %d is too small" , i , p .Size )
2930 }
30- if pieces [i ].Size > target {
31+ if pieces [i ].Size > maxSize {
3132 return cid .Undef , fmt .Errorf ("invalid Size of PieceInfo %d: value %d is larger than sector size of SealProofType %d" , i , p .Size , proofType )
3233 }
3334 if bits .OnesCount64 (uint64 (p .Size )) != 1 {
@@ -68,7 +69,7 @@ func GenerateUnsealedCID(proofType abi.RegisteredSealProof, pieces []abi.PieceIn
6869 )
6970 }
7071
71- for len (stack ) > 1 || stack [ 0 ]. Size < target {
72+ for len (stack ) > 1 {
7273 lastSize := stack [len (stack )- 1 ].Size
7374 stack = reduceStack (
7475 append (
@@ -81,7 +82,7 @@ func GenerateUnsealedCID(proofType abi.RegisteredSealProof, pieces []abi.PieceIn
8182 )
8283 }
8384
84- if stack [0 ].Size > target {
85+ if stack [0 ].Size > maxSize {
8586 return cid .Undef , fmt .Errorf ("provided pieces sum up to %d bytes, which is larger than sector size of SealProofType %d" , stack [0 ].Size , proofType )
8687 }
8788
0 commit comments