P3KI / bendy

A rust library for encoding and decoding bencode with enforced cannonicalization rules.
BSD 3-Clause "New" or "Revised" License
75 stars 14 forks source link

Relax the enforced correctness rules when decoding? #44

Open eugenesimakin opened 4 years ago

eugenesimakin commented 4 years ago

Hi folks,

I use Bendy in my project for decoding a bencode and it worked very well for me so far. But data on the Internet is not well-formed in all cases. So, I have some problems parsing bencode data which I'm getting from a server because this data is not well-formed (keys are not sorted). I can't tell the server to give me the response I want, because the server doesn't belong to me.

My question: Is there any way to relax the enforced correctness rules to be able to parse the response?

Thanks, Eugene

thequux commented 4 years ago

This is actually a feature that I've wanted to add, and have plans for how to do it. (Essentially, make the state tracker a type parameter of the encoder and decoder, and then define two additional state trackers: one that only enforces nesting, and one that does not enforce anything). I won't have time to work on this until 31 August, though, so if you want to work on it yourself, a good approach would be to organize your work into three pull requests:

  1. Separate the interface of the state tracker into a trait, and move the methods of the state tracker into an implementation of that trait.
  2. Parameterize the encoder and decoder with the state tracker object
  3. Implement a state tracker that doesn't enforce key order

That said, if the keys aren't sorted, then the server simply is not sending valid data, and this should be reported as a bug. Is the server in question public, so that I can gather test data and possibly fix the problem at the source?

morr0ne commented 3 years ago

Any update on this? I am having the same problem while implementing the bittorent protocol. Most trackers return unsorted keys. This is a huge blocker.

avdb13 commented 1 year ago

Three years later and this feature still hasn't been implemented. Anyone else looking into fixing this problem? Will try to make work out of it next week.