Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.1.0

Bug #3222 BitTorrent bencoding protocol errors
Submitted: 2005-01-17 19:08 UTC
From: uzume at xuno dot com Assigned: tacker
Status: Closed Package: File_Bittorrent
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  


 [2005-01-17 19:08 UTC] uzume at xuno dot com
Description: ------------ Encode.php can incorrently bencode dictionaries because the BitTorrent protocol specifies: "Keys must be strings and appear in sorted order (sorted as raw strings, not alphanumerics)." Also encoding and decoding does not properly encode and decode (most) strings as UTF-8 as specified in the new BitTorrent protocol. Please refer to the old and new BitTorrent protocol specifications at: http://bitconjurer.org/BitTorrent/protocol.html http://bittorrent.com/protocol.html

Comments

 [2005-01-31 12:54 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2005-02-07 01:05 UTC] uzume at xuno dot com
This is still broken. I now see code that uses asort() to sort arrays in the array encoding but this has even bigger problems. Dictionaries need be sorted by key and not by value (use ksort()). Technically, only dictionaries need to be sorted but it probably makes sense to have the lists' output by numeric value of the key (not a string sort though as you will note there is a natsort() for "natural" sorting too) so that the "first" item entered into the array is also the first item serialized. I recommend you move the sorting to later after you have identified whether the array is a dictionary or a list (and as I mentioned technically it is to be sorted by keys--not values, and only need be done for dictionaries).
 [2005-02-07 08:56 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2005-02-07 14:55 UTC] uzume at xuno dot com
It looks like you are doing the right thing now with respect to bencoding PHP arrays. I think I might personally go for a different implmentation but that is another issue than bugs in this software. In my original post about this bug I also mentioned that the BitTorrent specification now mentions that all fields are to be interpreted at UTF-8 now (vs. the original specification which stated ASCII in a few places but overrall did not state anything about all fields). This said there are several places where raw binary strings are required (so interpreting as UTF-8 is not appropriate), like in the peice hash values. Anyway, my point it that it would be nice if there was some easy mechanism to available to interpret the bdecoded data as UTF-8 (e.g., very useful for non-English filenames). I know several BitTorrent clients allow such to be interpreted in numberous ways because tradtionally this was not specified and people have generated torrent metafiles with various encodings (JIS, GB2312, etc.).
 [2005-02-07 16:25 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!