mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-19 22:58:30 +00:00
[#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
|
from types import DictType, IntType, ListType, LongType, StringType, TupleType
|
||||||
|
|
||||||
|
|
||||||
|
class BTFailure(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def decode_int(x, f):
|
def decode_int(x, f):
|
||||||
f += 1
|
f += 1
|
||||||
newf = x.index('e', f)
|
newf = x.index('e', f)
|
||||||
@ -71,9 +75,7 @@ def bdecode(x):
|
|||||||
try:
|
try:
|
||||||
r, l = decode_func[x[0]](x, 0)
|
r, l = decode_func[x[0]](x, 0)
|
||||||
except (IndexError, KeyError, ValueError):
|
except (IndexError, KeyError, ValueError):
|
||||||
raise Exception("not a valid bencoded string")
|
raise BTFailure("not a valid bencoded string")
|
||||||
if l != len(x):
|
|
||||||
raise Exception("invalid bencoded value (data after valid prefix)")
|
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ class TorrentInfo(object):
|
|||||||
with open(filename, "rb") as _file:
|
with open(filename, "rb") as _file:
|
||||||
self.__m_filedata = _file.read()
|
self.__m_filedata = _file.read()
|
||||||
self.__m_metadata = bencode.bdecode(self.__m_filedata)
|
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)
|
log.warning("Unable to open %s: %s", filename, ex)
|
||||||
raise ex
|
raise ex
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user