pasanlamahewa / rutorrent

Automatically exported from code.google.com/p/rutorrent
0 stars 0 forks source link

Zero length file entry create in file list when creating a torrent from directory/folder #900

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Right click on a directory in file manager tab and select create new .torrent

What is the expected output? What do you see instead?
files in directory are listed as <dir path>//<filename>

What environment are you using?
1. ruTorrent version is 3.6 svn 2404
2. rTorrent version is... 0.9.3/0.13.3
3. lighttpd 1.4.29 on debian
4. chromium

Are some errors present in the web-server log?
No
Are some errors present in the browser error console?
No
Please provide any additional information below.
The extra '/' ends up creating a zero length string in the torrent file. Some 
sites are not able to handle the zero length string and interpret it as a file.

The problem is in Torrent.php in the 'folder' function. The function sets 
$this->basedir and then strips any trailing '/' off. But it then calls the 
'files' function with $dir which still has the trailing slash in place. Within 
the 'files' function, a '/' is added between the base path and each file name. 
This results in the double '/'.

The fix is pretty simple. Pass $this->basedir into the files function instead 
of $dir since $this->basedir has had any trailing slashes removed.

Here is the fix:
private function folder( $dir, $piece_length )
{
    $this->basedir = $dir;
    $len = strlen($this->basedir);
    if(($len>1) && ($this->basedir[$len-1]=='/'))
        $this->basedir = substr($this->basedir,0,-1);
    return($this->files( self::scandir( $this->basedir ), $piece_length));
}

The problem above ends up creating a list with the first element being a zero 
length string. Since there should never be a valid reason to have a zero length 
string in the bencoded data, we can avoid it (and any other place where a zero 
length string might get created) by checking the length of the string at 
encoding time and return an empty string instead of a "0:" string.

Fix:
static private function encode_string( $string ) 
{
    if( strlen( $string ))
        return(strlen( $string ) . ':' . $string);
    else
        return "";
}

Original issue reported on code.google.com by beastly...@gmail.com on 29 Mar 2014 at 7:24

GoogleCodeExporter commented 9 years ago
You can also change the torrent creation configuration to mktorrent.

Original comment by doctor...@gmail.com on 14 Jul 2014 at 8:42

GoogleCodeExporter commented 9 years ago
Yes. There are alternatives. I was just trying to provide a fix for code that 
doesn't work.

Original comment by beastly...@gmail.com on 24 Jul 2014 at 6:39

GoogleCodeExporter commented 9 years ago

Original comment by novik65 on 25 Jul 2014 at 10:54

GoogleCodeExporter commented 9 years ago
>Since there should never be a valid reason to have a zero length string in the 
bencoded data

This is an incorrect assumption. Example:

Fragment from valid torrent:

comment45:Please seed this torrent as long as 
possible!13:comment.utf-80:10:created by

Fragment from invalid torrent (i.e. created with your patch):

comment45:Please seed this torrent as long as 
possible!13:comment.utf-810:created by

Original comment by novik65 on 26 Jul 2014 at 8:11

GoogleCodeExporter commented 9 years ago
Doh. Of course. Very bad assumption on my part. My apologies.

Original comment by beastly...@gmail.com on 26 Jul 2014 at 6:11