Fix GH-10370: File corruption in _php_stream_copy_to_stream_ex when using copy_file_range (#10440)

copy_file_range can return early without copying all the data. This is
legal behaviour and worked properly, unless the mmap fallback was used.
The mmap fallback would read too much data into the destination,
corrupting the destination file. Furthermore, if the mmap fallback would
fail and have to fallback to the regular file copying mechanism, a
similar issue would occur because both maxlen and haveread are modified.
Furthermore, there was a mmap-resource in one of the failure paths of
the mmap fallback code.
This patch fixes these issues. This also adds regression tests using the
new copy_file_range early-return simulation added in the previous
commit.
This commit is contained in:
Niels Dossche 2023-02-10 13:08:44 +01:00 committed by GitHub
parent 81aedad452
commit b4db690cb3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 170 additions and 4 deletions

View file

@ -53,6 +53,7 @@ ZEND_BEGIN_MODULE_GLOBALS(zend_test)
int replace_zend_execute_ex;
int register_passes;
bool print_stderr_mshutdown;
zend_long limit_copy_file_range;
zend_test_fiber *active_fiber;
zend_long quantity_value;
zend_string *str_test;