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

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

Closed
nicobubulle opened this issue Aug 22, 2014 · 5 comments

Comments

@nicobubulle
Copy link
Collaborator

From beastly...@gmail.com on March 29, 2014 20:24:20

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

// 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: http://code.google.com/p/rutorrent/issues/detail?id=900

@nicobubulle
Copy link
Collaborator Author

From doctor...@gmail.com on July 14, 2014 13:42:38

You can also change the torrent creation configuration to mktorrent.

@nicobubulle
Copy link
Collaborator Author

From beastly...@gmail.com on July 24, 2014 11:39:25

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

@nicobubulle
Copy link
Collaborator Author

From novik65 on July 25, 2014 03:54:08

Status: Fixed

@nicobubulle
Copy link
Collaborator Author

From novik65 on July 26, 2014 01:11:00

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

@nicobubulle
Copy link
Collaborator Author

From beastly...@gmail.com on July 26, 2014 11:11:00

Doh. Of course. Very bad assumption on my part. My apologies.

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

1 participant