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

Bug #5836 Missing support for >2GB files
Submitted: 2005-10-31 15:47 UTC Modified: 2006-09-04 04:00 UTC
From: brian at matzon dot dk Assigned: tacker
Status: Closed Package: File_Bittorrent
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  


 [2005-10-31 15:47 UTC] brian at matzon dot dk
Description: ------------ Unable to properly decode torrents with >2GB files. problem is _decode_int() which uses intval. It should be using floatval. I manually changed to that, but then getStats failed. I was unable to determine the issue with getStats.

Comments

 [2006-01-18 11:30 UTC] alexiev at gmail dot com
Besides the change in Decode.php, a change in Encode.php is required: the "double" type showld be treated the same as "integer" type, in order the encoding to work with numbers, greated than 2GB! I will try to provide a patch shortly.
 [2006-01-18 11:50 UTC] alexiev at gmail dot com
Here is the patch: File File_Bittorrent_issue5836.patch diff -u Bittorrent/Decode.php Bittorrent_Fix/Decode.php --- Bittorrent/Decode.php 2006-01-18 18:34:58.000000000 +0200 +++ Bittorrent_Fix/Decode.php 2006-01-18 18:21:17.000000000 +0200 @@ -362,7 +362,7 @@ function _decode_int() { $pos_e = strpos($this->_source, 'e', $this->_position); - $return = intval(substr($this->_source, $this->_position, $pos_e - $this->_position)); + $return = floatval(substr($this->_source, $this->_position, $pos_e - $this->_position)); $this->_position = $pos_e + 1; return $return; } diff -u Bittorrent/Encode.php Bittorrent_Fix/Encode.php --- Bittorrent/Encode.php 2006-01-18 18:34:58.000000000 +0200 +++ Bittorrent_Fix/Encode.php 2006-01-18 18:35:50.000000000 +0200 @@ -81,8 +81,9 @@ case 'string': return $this->encode_string($mixed); break; + case 'double': case 'integer': - return $this->encode_int($mixed); + return $this->encode_int(round($mixed)); break; case 'array': return $this->encode_array($mixed); Usage: cd /usr/share/php/File/Bittorrent; patch -p1 < /path/to/File_Bittorrent_issue5836.patch
 [2006-01-18 12:00 UTC] alexiev at gmail dot com
Please, have in mind, the floatval function is present in PHP 4 >= 4.2.0 and PHP 5, so in order to keep the package requirements (PHP 4 >= 4.0.0), a call to PHP_Compat::loadFunction('floatval') showld be made in the Decode.php file.
 [2006-01-20 09:24 UTC] alexiev at gmail dot com
There is a flaw in the above patch: all int fields are decoded to float vars (even if the number is less than 2G). Here is the patch, that only decodes as float if the number would oveflow the int var: diff -u Bittorrent/Decode.php Bittorrent_Fix/Decode.php --- Bittorrent/Decode.php 2006-01-20 16:07:02.000000000 +0200 +++ Bittorrent_Fix/Decode.php 2006-01-20 16:14:19.000000000 +0200 @@ -362,7 +362,15 @@ function _decode_int() { $pos_e = strpos($this->_source, 'e', $this->_position); - $return = intval(substr($this->_source, $this->_position, $pos_e - $this->_position)); + + /** + * The return value showld be automatically casted to fload if the intval would + * overflow. The "+ 0" accomplishes exactly that, using the internal casting + * logic of PHP + * + * Fixed by SASh + */ + $return = substr($this->_source, $this->_position, $pos_e - $this->_position) + 0; $this->_position = $pos_e + 1; return $return; } diff -u Bittorrent/Encode.php Bittorrent_Fix/Encode.php --- Bittorrent/Encode.php 2006-01-20 16:07:02.000000000 +0200 +++ Bittorrent_Fix/Encode.php 2006-01-18 18:35:50.000000000 +0200 @@ -81,8 +81,9 @@ case 'string': return $this->encode_string($mixed); break; + case 'double': case 'integer': - return $this->encode_int($mixed); + return $this->encode_int(round($mixed)); break; case 'array': return $this->encode_array($mixed);
 [2006-01-20 09:46 UTC] tacker at php dot net
Good, I will test the patch this weekend even if I hate testing it because of the time every run takes.
 [2006-09-04 04:00 UTC] tacker at php dot net (Markus Tacker)
Thank you for your bug report. This issue has been fixed in the latest released version of the package, which you can download at http://pear.php.net/get/File_Bittorrent