[#2900] Fix Error loading torrent: invalid bencoded value

* Testing the torrent with other bencode libs doesn't raise exceptions
   so just revert the 'small fix' applied in b193d87499.
 * Add BTFailure exception so bdecode issue can be caught in deluge code.
This commit is contained in:
bendikro 2016-10-11 18:29:21 +02:00 committed by Calum Lind
parent 5607bb3d61
commit 41fed16d08
2 changed files with 6 additions and 4 deletions

View File

@ -15,6 +15,10 @@
from types import DictType, IntType, ListType, LongType, StringType, TupleType
class BTFailure(Exception):
pass
def decode_int(x, f):
f += 1
newf = x.index('e', f)
@ -71,9 +75,7 @@ def bdecode(x):
try:
r, l = decode_func[x[0]](x, 0)
except (IndexError, KeyError, ValueError):
raise Exception("not a valid bencoded string")
if l != len(x):
raise Exception("invalid bencoded value (data after valid prefix)")
raise BTFailure("not a valid bencoded string")
return r

View File

@ -74,7 +74,7 @@ class TorrentInfo(object):
with open(filename, "rb") as _file:
self.__m_filedata = _file.read()
self.__m_metadata = bencode.bdecode(self.__m_filedata)
except Exception as ex:
except bencode.BTFailure as ex:
log.warning("Unable to open %s: %s", filename, ex)
raise ex