xref: /PHP-8.4/ext/zend_test/tests/gh10370_4.phpt (revision 10f23785)
1--TEST--
2GH-10370: File corruption in _php_stream_copy_to_stream_ex when using copy_file_range - unlimited copy using stream_copy_to_stream
3--EXTENSIONS--
4zend_test
5--SKIPIF--
6<?php
7if (PHP_OS != 'Linux') {
8    die('skip For Linux only');
9}
10?>
11--INI--
12zend_test.limit_copy_file_range=4096
13--FILE--
14<?php
15/* Note: the value 4096 is chosen so that the mmap in _php_stream_copy_to_stream_ex() will mmap
16 *       at an offset of a multiple of 4096, which is the standard page size in most Linux systems. */
17
18$input = fopen(__DIR__ . DIRECTORY_SEPARATOR . 'gh10370.tar', 'r');
19$output = fopen(__DIR__ . DIRECTORY_SEPARATOR . 'gh10370_004_out.tar', 'w');
20
21var_dump(stream_copy_to_stream($input, $output));
22
23fclose($input);
24fclose($output);
25
26var_dump(sha1_file(__DIR__ . DIRECTORY_SEPARATOR . 'gh10370.tar'));
27var_dump(sha1_file(__DIR__ . DIRECTORY_SEPARATOR . 'gh10370_004_out.tar'));
28?>
29--EXPECT--
30int(11776)
31string(40) "edcad8cd6c276f5e318c826ad77a5604d6a6e93d"
32string(40) "edcad8cd6c276f5e318c826ad77a5604d6a6e93d"
33--CLEAN--
34<?php
35@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'gh10370_004_out.tar');
36?>
37