]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix issue #112
authorMatt Joiner <anacrolix@gmail.com>
Mon, 12 Sep 2016 06:54:43 +0000 (16:54 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 12 Sep 2016 06:54:43 +0000 (16:54 +1000)
misc.go

diff --git a/misc.go b/misc.go
index 42a65fe7d27314fec3244c225d3be85f23334951..a9b024ec4c7f9a2cccfb39dd25bf8f68d277e5e9 100644 (file)
--- a/misc.go
+++ b/misc.go
@@ -62,8 +62,14 @@ func validateInfo(info *metainfo.Info) error {
        if len(info.Pieces)%20 != 0 {
                return errors.New("pieces has invalid length")
        }
-       if int((info.TotalLength()+info.PieceLength-1)/info.PieceLength) != info.NumPieces() {
-               return errors.New("piece count and file lengths are at odds")
+       if info.PieceLength == 0 {
+               if info.TotalLength() != 0 {
+                       return errors.New("zero piece length")
+               }
+       } else {
+               if int((info.TotalLength()+info.PieceLength-1)/info.PieceLength) != info.NumPieces() {
+                       return errors.New("piece count and file lengths are at odds")
+               }
        }
        return nil
 }