xref: /PHP-7.4/ext/standard/tests/file/bug81145.phpt (revision 99e7c5ce)
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--FILE--
17<?php
18$src = __DIR__ . "/bug81145_src.bin";
19$dst = __DIR__ . "/bug81145_dst.bin";
20define('SIZE_4G', 0x100000000);
21
22//Create file and append random content at the 4GB boundary
23if (PHP_OS_FAMILY !== "Windows") {
24    exec("fallocate -l " . (SIZE_4G-0x100) . " " . escapeshellarg($src));
25} else {
26    exec("fsutil file createnew " . escapeshellarg($src) . " " . (SIZE_4G-0x100));
27}
28$fp = fopen($src, "ab");
29fwrite($fp, random_bytes(0x200));
30fclose($fp);
31copy($src, $dst);
32if (filesize($src) !== filesize($dst)) {
33    die("Files have different sizes!");
34}
35$f1 = fopen($src,'rb') or die("src open failed");
36$f2 = fopen($dst,'rb') or die("dst open failed");
37
38//Seek to 4 GB boundary, as this is the location where the problem occurs
39fseek($f1, SIZE_4G - 0x100, SEEK_SET);
40fseek($f2, SIZE_4G - 0x100, SEEK_SET);
41echo (fread($f1,0x200) === fread($f2,0x200) ? "Identical" : "Copy failed");
42fclose($f1);
43fclose($f2);
44?>
45--CLEAN--
46<?php
47@unlink(__DIR__ . "/bug81145_src.bin");
48@unlink(__DIR__ . "/bug81145_dst.bin");
49?>
50--EXPECT--
51Identical
52