[Debtorrent-commits] r49 - /debtorrent/trunk/DebTorrent/BT1/btformats.py

camrdale-guest at users.alioth.debian.org camrdale-guest at users.alioth.debian.org
Thu May 17 05:59:50 UTC 2007


Author: camrdale-guest
Date: Thu May 17 05:59:50 2007
New Revision: 49

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=49
Log:
Add assertion to check that file boundaries are piece boundaries

Modified:
    debtorrent/trunk/DebTorrent/BT1/btformats.py

Modified: debtorrent/trunk/DebTorrent/BT1/btformats.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/BT1/btformats.py?rev=49&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/BT1/btformats.py (original)
+++ debtorrent/trunk/DebTorrent/BT1/btformats.py Thu May 17 05:59:50 2007
@@ -6,6 +6,7 @@
 
 from types import StringType, LongType, IntType, ListType, DictType
 from re import compile
+from bisect import bisect
 
 reg = compile(r'^[^/\\.~][^/\\]*$')
 
@@ -20,20 +21,28 @@
     piecelengths = info.get('piece lengths')
     if type(piecelengths) != ListType:
         raise ValueError
+    total_length = 0L
+    piece_bounds = [0L]
     for length in piecelengths:
         if type(length) not in ints or length <= 0:
             raise ValueError, 'bad metainfo - bad piece length'
+        total_length += length
+        piece_bounds.append(total_length)
     if info.has_key('files') == info.has_key('length'):
         raise ValueError, 'single/multiple file mix'
     files = info.get('files')
     if type(files) != ListType:
         raise ValueError
+    total_length = 0L
     for f in files:
         if type(f) != DictType:
             raise ValueError, 'bad metainfo - bad file value'
         length = f.get('length')
         if type(length) not in ints or length < 0:
             raise ValueError, 'bad metainfo - bad length'
+        total_length += length
+        if piece_bounds[bisect(piece_bounds,total_length)-1] != total_length:
+            raise ValueError, 'bad metainfo - file does not end on piece boundary'
         path = f.get('path')
         if type(path) != ListType or path == []:
             raise ValueError, 'bad metainfo - bad path'




More information about the Debtorrent-commits mailing list