php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30529 ftp_size() does not return values larger than 2^31
Submitted: 2004-10-22 12:18 UTC Modified: 2004-10-22 14:18 UTC
From: wittj at gmx dot net Assigned:
Status: Not a bug Package: FTP related
PHP Version: 5.0.2 OS: linux-2.6.8-ck4
Private report: No CVE-ID: None
 [2004-10-22 12:18 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-22 12:50 UTC] 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 13:11 UTC] 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 13:25 UTC] 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 14:18 UTC] wittj at gmx dot net
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));
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Jan 27 22:03:33 2022 UTC