From 6684d94fcafeb905accf8b18e8e9c3f2060d9346 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Thu, 9 Feb 2023 22:24:18 +0100 Subject: [PATCH] Fix GH-10548: copy() fails on cifs mounts because of incorrect length (cfr_max) specified in streams.c:1584 copy_file_range() On some filesystems, the copy operation fails if we specify a size larger than the file size in certain circumstances and configurations. In those cases EIO will be returned as errno and we will therefore fall back to other methods. --- main/streams/streams.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/main/streams/streams.c b/main/streams/streams.c index de53e483c62b..4cd211ad85fe 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1614,6 +1614,13 @@ PHPAPI zend_result _php_stream_copy_to_stream_ex(php_stream *src, php_stream *de /* not implemented by this Linux kernel */ break; + case EIO: + /* Some filesystems will cause failures if the max length is greater than the file length + * in certain circumstances and configuration. In those cases the errno is EIO and we will + * fall back to other methods. We cannot use stat to determine the file length upfront because + * that is prone to races and outdated caching. */ + break; + default: /* unexpected I/O error - give up, no fallback */ *len = haveread;