[php-src] Issue #15034: Integer overflow on stream_notification_callback byte_max parameter with files bigger than 2GB

From: Date: Fri, 19 Jul 2024 19:39:29 +0000
Subject: [php-src] Issue #15034: Integer overflow on stream_notification_callback byte_max parameter with files bigger than 2GB
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-247328@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/15034 Author: yortx ### Description Downloading a file from an http url using _fopen_, and trying to keep track of download progress using the _stream_notification_callback_ returns a negative value in the _$bytes_max_ parameter if the file to download is bigger than 2GB. Looks like an integer overflow. The _$bytes_transferred_ parameter, on the other hand, reports the size transferred correctly. The following code: ```php <?php $params = ['notification' => function( int $notification_code, int $severity, ?string $message, int $message_code, int $bytes_transferred, int $bytes_max ) { fwrite(STDERR, "Downloaded {$bytes_transferred} out of {$bytes_max}\n"); }]; $contextResource = \stream_context_create([], $params); $url = "https://laotzu.ftp.acc.umu.se/cdimage/archive/12.5.0/amd64/iso-dvd/debian-12.5.0-amd64-DVD-1.iso"; $resource = \fopen((string) $url, 'r', false, $contextResource); while(!feof($resource)) { fread($resource, 1024*1024); } ``` Resulted in this output: ``` Downloaded 0 out of -301989888 Downloaded 7937 out of -301989888 Downloaded 15937 out of -301989888 Downloaded 23937 out of -301989888 ... Downloaded 3992977408 out of -301989888 ``` But I expected this output instead: ``` Downloaded 0 out of 3992977408 Downloaded 7956 out of 3992977408 ... Downloaded 3992977408 out of 3992977408 ``` My system is amd 64bits. The problem only happens when the file to download is bigger than 2GB, as it is with the iso image I used in the example (which is near 4GB in size). ### PHP Version PHP 8.2.20 ### Operating System GNU/Debian 12.6

« previous php.bugs (#247328) next »