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