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.
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 atry:
/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.