1--TEST-- 2Bug #81145 (copy() and stream_copy_to_stream() fail for +4GB files) 3--SKIPIF-- 4<?php 5if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); 6if (PHP_INT_SIZE !== 8) die("skip this test is for 64bit platforms only"); 7if (disk_free_space(__DIR__) < 0x220000000) die("skip insuffient disk space"); 8if (PHP_OS_FAMILY !== "Windows") { 9 $src = __DIR__ . "/bug81145_src.bin"; 10 define('SIZE_4G', 0x100000000); 11 exec("fallocate -l " . (SIZE_4G-0x100) . " " . escapeshellarg($src), $output, $status); 12 if ($status !== 0) die("skip fallocate() not supported"); 13 @unlink(__DIR__ . "/bug81145_src.bin"); 14} 15?> 16--CONFLICTS-- 17all 18--FILE-- 19<?php 20$src = __DIR__ . "/bug81145_src.bin"; 21$dst = __DIR__ . "/bug81145_dst.bin"; 22define('SIZE_4G', 0x100000000); 23 24//Create file and append random content at the 4GB boundary 25if (PHP_OS_FAMILY !== "Windows") { 26 exec("fallocate -l " . (SIZE_4G-0x100) . " " . escapeshellarg($src)); 27} else { 28 exec("fsutil file createnew " . escapeshellarg($src) . " " . (SIZE_4G-0x100)); 29} 30$fp = fopen($src, "ab"); 31fwrite($fp, random_bytes(0x200)); 32fclose($fp); 33copy($src, $dst); 34if (filesize($src) !== filesize($dst)) { 35 die("Files have different sizes!"); 36} 37$f1 = fopen($src,'rb') or die("src open failed"); 38$f2 = fopen($dst,'rb') or die("dst open failed"); 39 40//Seek to 4 GB boundary, as this is the location where the problem occurs 41fseek($f1, SIZE_4G - 0x100, SEEK_SET); 42fseek($f2, SIZE_4G - 0x100, SEEK_SET); 43echo (fread($f1,0x200) === fread($f2,0x200) ? "Identical" : "Copy failed"); 44fclose($f1); 45fclose($f2); 46?> 47--CLEAN-- 48<?php 49@unlink(__DIR__ . "/bug81145_src.bin"); 50@unlink(__DIR__ . "/bug81145_dst.bin"); 51?> 52--EXPECT-- 53Identical 54