Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential parsing error in _parse_url function. #12

Open
drew2a opened this issue Jan 12, 2024 · 0 comments
Open

Potential parsing error in _parse_url function. #12

drew2a opened this issue Jan 12, 2024 · 0 comments

Comments

@drew2a
Copy link

drew2a commented Jan 12, 2024

I'm not familiar with magnet2torrent, so my assumptions could be incorrect. I've just read the code of the following function:

def _parse_url(self):
url = urlparse(self.magnet_link)
url_query = parse_qs(url.query)
infohash = url_query["xt"][0].split(":")[2]
if len(infohash) == 40:
infohash = binascii.unhexlify(infohash)
elif len(infohash) == 32:
infohash = base64.b32decode(infohash)
else:
raise Exception("Unable to parse infohash")
trackers = url_query.get("tr", [])
name = url_query.get("dn")
if name:
name = name[0]
else:
name = binascii.hexlify(infohash).decode()
return infohash, trackers, name

I noticed there might be an issue in the line:

infohash = url_query["xt"][0].split(":")[2]

As it doesn't differentiate between hash types. It could be urn:sha1, urn:ed2khash, urn:btih, etc. However, only btih is compatible with BitTorrent.

Ref:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant