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

Decode exception when decoding string from http://bttracker.debian.org/ #10

Open
mikewolfxyou opened this issue Jan 16, 2021 · 4 comments
Assignees

Comments

@mikewolfxyou
Copy link

mikewolfxyou commented Jan 16, 2021

Hi,

Just found may be an issue, when I try to use bencode.decode some string from debian bttracker, always got exception.

How to reproduce:

Make a get call use following url:
http://bttracker.debian.org:6969/announce?info_hash=N%f5%ad%16%c0%9e%b5%0b%8c%3b%90~%02u%24%eeC%ad%ad%01&peer_id=%ff%fe%fd%fc%fb%fa%f9%f8%f7%f6%f5%f4%f3%f2%f1%f0%ef%ee%ed%ec&port=6881&uploaded=0&downloaded=0&left=659554304%22

then will get following UTF_8 String back:

"d8:intervali900e5:peers2:ip13:213.49.181.984:porti6881e2:ip14:216.195.129.274:porti6881e2:ip12:146.71.73.214:porti6881e2:ip12:146.71.73.514:porti6881eee"

When I try to decode the above string,

Bencode bencode = new Bencode(StandardCharsets.UTF_8, true);
bencode.decode("d8:intervali900e5:peers2:ip13:213.49.181.984:porti6881e2:ip14:216.195.129.274:porti6881e2:ip12:146.71.73.214:porti6881e2:ip12:146.71.73.514:porti6881eee".getBytes(StandardCharsets.UTF_8,), Type.DICTIONARY);

then got an exception:

"Unexcept token 'i'"

I try to debug it, then found out that "d8:" these 3 chars are ok, till the fourth chars "i", then got the exception.

I just want to confirm, if it is the string encode problem? or something else?

btw: Env: Java 11, Mac OS. I use the example string in the README.md, the decoding works fine.

Thank you for your help!

best regards

Mike

@dampcake
Copy link
Owner

I am trying to understand how this is formatted. Right now parsing it manually by hand to JSON:

{
  "interval": 900,
  "peers": "ip",
  "213.49.181.984": "port", // also this is not a valid IP address
  //This is where it fails. A number cannot be a key in a bencode dict
}

I have also tried running it through a some other bencode parsers and they all fail at the same spot. Are you actually able to get it decode with anything? As far as I can tell it is malformed. If you are able to get it to decode please let me know.

My guess is that the peers are supposed an array of dictionaries as that is what would make the most logic sense but that is not what the data specifies.

@dampcake dampcake self-assigned this Jan 16, 2021
@blanexie
Copy link

请考虑下中文编码的问题, 还有种子文件中的pieces字段的值

  1. Consider Chinese encoding

  2. torrent --> info --> pieces

@dampcake
Copy link
Owner

@blanexie Chinese characters should parse fine as long as you pass a Charset that can understand them. Do you have an example of valid bencode formatting with those characters in a string that is not parsing correctly?

@blanexie
Copy link

blanexie commented Dec 7, 2021

thanks , It's normal to run.

  1. useBytes : true
  2. ByteBuffer to convert into String

kotlin code

val bencode = Bencode(charset("utf8"), true)


 UTF8.decode((infoMap["name"] as ByteBuffer)).toString()

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

No branches or pull requests

3 participants