#30529 [Bgs]: ftp_size() does not return values larger than 2^31

From: Date: Fri, 22 Oct 2004 12:19:27 +0000
Subject: #30529 [Bgs]: ftp_size() does not return values larger than 2^31
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-67953@lists.php.net to get a copy of this message
ID: 30529 User updated by: wittj at gmx dot net Reported By: wittj at gmx dot net Status: Bogus Bug Type: FTP related Operating System: linux-2.6.8-ck4 PHP Version: 5.0.2 New Comment: Sorry if I bother you, but I thought that you might be interested in a solution to my problem. I append a patch that transforms ftp_size() to return a float. This works very well for me and is exactly what I was looking for in the first place. I don't know the PHP code well, so this might break everything and make your grandma disappear, but as I said it works well for me and might also be useful to others. I did not notice any inaccuracies, it reports the file size exactly up to the last bit. diff -r php-5.0.2-orig/ext/ftp/ftp.c php-5.0.2/ext/ftp/ftp.c 981c981 < int --- > double 996c996 < return atoi(ftp->inbuf); --- > return atof(ftp->inbuf); diff -r php-5.0.2-orig/ext/ftp/ftp.h php-5.0.2/ext/ftp/ftp.h 180c180 < int ftp_size(ftpbuf_t *ftp, const char *path); --- > double ftp_size(ftpbuf_t *ftp, const char *path); diff -r php-5.0.2-orig/ext/ftp/php_ftp.c php-5.0.2/ext/ftp/php_ftp.c 1037c1037 < /* {{{ proto int ftp_size(resource stream, string filename) --- > /* {{{ proto double ftp_size(resource stream, string filename) 1053c1053 < RETURN_LONG(ftp_size(ftp, file)); --- > RETURN_DOUBLE(ftp_size(ftp, file)); Previous Comments: ------------------------------------------------------------------------ [2004-10-22 13:25:09] derick@php.net Because it won't be accurate anymore due to you can not store the precision you want in a float. ------------------------------------------------------------------------ [2004-10-22 13:11:59] wittj at gmx dot net Sorry, I did not know that. I mean, I did know that ints on my system are limited to 32 bits (31 plus sign), but I always thought that php could handle numbers larger than that. Maybe a silly question: why does $number = 4190578688; print $number."<br/>"; print $number + 10; work then? With var_dump() I see that $number is treated as a float value. Why can't ftp_size() just return a float then? Not being able to recognize files larger than 2GB seems somewhat dated to me. No offense - I just wonder why this doesn't work. Thank you. ------------------------------------------------------------------------ [2004-10-22 12:50:48] derick@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php PHP does not support numbers > 2^31 at this moment. ------------------------------------------------------------------------ [2004-10-22 12:18:37] wittj at gmx dot net Description: ------------ On my FTP server I have a file which is about 4GB large. The FTP server (vsftpd) reports the file size correctly (checked with sniffer), however ftp_size() does only return a size of 2147483647 (2^31) bytes. Obviously ftp_size() does not support files larger than that, as I get the same result on other large files. Reproduce code: --------------- $conn_id = ftp_connect($server); $contents = ftp_nlist($conn_id, "."); foreach($contents as $file) { print ftp_size($conn_id, $file); } Expected result: ---------------- The correct file size Actual result: -------------- A file size of 2^31 bytes. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=30529&edit=1

« previous php.bugs (#67953) next »