Browse Source

Crash for explainable reason when protocol is out of sync (version skew)

Jakob Borg 12 years ago
parent
commit
e86296884a
2 changed files with 6 additions and 1 deletions
  1. 1 1
      main.go
  2. 5 0
      protocol/marshal.go

+ 1 - 1
main.go

@@ -153,7 +153,7 @@ func main() {
 	// Walk the repository and update the local model before establishing any
 	// connections to other nodes.
 
-	infoln("Iniial repository scan in progress")
+	infoln("Initial repository scan in progress")
 	loadIndex(m)
 	updateLocalModel(m)
 

+ 5 - 0
protocol/marshal.go

@@ -91,6 +91,11 @@ func (r *marshalReader) readBytes() []byte {
 	if r.err != nil {
 		return nil
 	}
+	if l > 10*1<<20 {
+		// Individual blobs in BEP are not significantly larger than BlockSize.
+		// BlockSize is not larger than 1MB.
+		panic("too large read - protocol error or out of sync")
+	}
 	b := buffers.Get(l + pad(l))
 	_, r.err = io.ReadFull(r.r, b)
 	r.tot += int(l + pad(l))