xref: /php-src/ext/zend_test/tests/gh10370_3.phpt (revision 10f23785)
1--TEST--
2GH-10370: File corruption in _php_stream_copy_to_stream_ex when using copy_file_range - partial 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=3584
13--FILE--
14<?php
15/* Note: the value 3584 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. */
17mkdir(__DIR__ . DIRECTORY_SEPARATOR . 'gh10370_003');
18
19$input = fopen(__DIR__ . DIRECTORY_SEPARATOR . 'gh10370.tar', 'r');
20$output = fopen(__DIR__ . DIRECTORY_SEPARATOR . 'gh10370_003' . DIRECTORY_SEPARATOR . 'testfile', 'w');
21
22var_dump(stream_copy_to_stream($input, $output, 10240, 0x200));
23
24fclose($input);
25fclose($output);
26
27var_dump(sha1_file(__DIR__ . DIRECTORY_SEPARATOR . 'gh10370_003' . DIRECTORY_SEPARATOR . 'testfile'));
28?>
29--EXPECT--
30int(10240)
31string(40) "a723ae4ec7eababff73ca961a771b794be6388d2"
32--CLEAN--
33<?php
34@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'gh10370_003' . DIRECTORY_SEPARATOR . 'testfile');
35@rmdir(__DIR__ . DIRECTORY_SEPARATOR . 'gh10370_003');
36?>
37