effigies / BitTornado

UNMAINTAINED - John Hoffman's fork of the original bittorrent
Other
150 stars 44 forks source link

Invalid key: path.utf-8 #46

Closed Yuuki2012 closed 8 years ago

Yuuki2012 commented 8 years ago

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/BitTornado/BitTornado/Network/RawServer.py", line 109, in listen_forever
    func()
  File "/home/BitTornado/BitTornado/Tracker/track.py", line 1123, in parse_allowed
    [".torrent"])
  File "/home/BitTornado/BitTornado/Application/parsedir.py", line 81, in parsedir
    torrentinfo, infohash = parse_torrent(path, return_metainfo)
  File "/home/BitTornado/BitTornado/Application/parsedir.py", line 163, in parse_torrent
    data = MetaInfo.read(path)
  File "/home/BitTornado/BitTornado/Meta/bencode.py", line 203, in read
    **kwargs)
  File "/home/BitTornado/BitTornado/Meta/Info.py", line 408, in __init__
    super(MetaInfo, self).__init__(*args, **kwargs)
  File "/home/BitTornado/BitTornado/Meta/TypedCollections.py", line 88, in __init__
    self[k] = v
  File "/home/BitTornado/BitTornado/Meta/TypedCollections.py", line 114, in __setitem__
    val = self.typemap[key](val)
  File "/home/BitTornado/BitTornado/Meta/Info.py", line 227, in __init__
    self['files'] = params['files']
  File "/home/BitTornado/BitTornado/Meta/TypedCollections.py", line 114, in __setitem__
    val = self.typemap[key](val)
  File "/home/BitTornado/BitTornado/Meta/TypedCollections.py", line 10, in __init__
    self.extend(iterable)
  File "/home/BitTornado/BitTornado/Meta/TypedCollections.py", line 56, in extend
    self.append(val)
  File "/home/BitTornado/BitTornado/Meta/TypedCollections.py", line 25, in append
    val = self.valtype(val)
  File "/home/BitTornado/BitTornado/Meta/TypedCollections.py", line 88, in __init__
    self[k] = v
  File "/home/BitTornado/BitTornado/Meta/TypedCollections.py", line 119, in __setitem__
    raise KeyError('Invalid key: ' + key)
KeyError: 'Invalid key: path.utf-8'

I'm not sure what causes this... it happens when I try to start the tracker.

effigies commented 8 years ago

Looks like a malformed .torrent file where a path entry is encoded as path.utf-8. Are you able to post the .torrent file somewhere I could have a look?

I'll look into this as I can. Should probably give a better error message, at the very least.

Yuuki2012 commented 8 years ago

http://shiro.yuuki-chan.xyz/846889.torrent

Here's the torrent, it's not made by me, but it's made with Vuze, I think this is the problem here.

effigies commented 8 years ago

Oh, I see. Thanks a lot.

from BitTornado.Meta.bencode import BencodedFile

class TestOpen(BencodedFile, dict):
    pass

metainfo = TestOpen.read('846889.torrent')

Yeah, it looks like the metainfo has the following keys:

['encoding', 'creation date', 'announce-list', 'announce', 'info',
 'created by', 'comment', 'azureus_properties', 'comment.utf-8']

metainfo['info'] has:

['files', 'pieces', 'private', 'name.utf-8', 'piece length', 'name']

metainfo['info']['files'][0] has:

['path', 'length', 'path.utf-8']

I think the best way to go about this in the short term is to whitelist these '.utf-8' keys, as well as that azureus_properties. That way modifying the file doesn't necessarily remove them.