[#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:
parent
5607bb3d61
commit
41fed16d08
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue