JohnDoee / magnet2torrent

Turn a bittorrent magnet link into a .torrent file
MIT License
60 stars 9 forks source link

Prevent exception during unpacking of UDP "announce" message #4

Closed hph86 closed 4 years ago

hph86 commented 4 years ago

During the unpacking of a UDP "announce" message, an unhandled exception may occur if the message being unpacked is too short: https://github.com/JohnDoee/magnet2torrent/blob/93e85dc65a5a0e42084515d54828668fa7c40c61/src/magnet2torrent/udptracker.py#L66

This can be prevented either by wrapping the unpack() into a try:/except: block or by checking the message size beforehand. Other parts of the code seem to make use of the latter option. Hence, the second commit of this PR adds a size check to the unpacking of the "announce" message while the first tries to add more semantics to the handler function.

JohnDoee commented 4 years ago

Thanks for fixing it and improving the check code.