Fix streams copy length after partial copy_file_range. #10538
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
it seems that on some file systems (here, BTRFS),
copy_file_range
succeeds but does not copy the whole file. Then, we fall back to a second method that tries to copymaxlen
bytes from the current location. Since the copy succeeded in the previous attempt, the file pointer was moved, butmaxlen
is not updated, so more bytes than expected are copied from the file.This caused a failure for me in several phar tests, as
ext/phar/phar.c
checks for how much was copied, in addition to the success returned by the function, even in that case. After applying the patch, these tests now all pass.If the first method is not attempted, fails or copies 0 bytes,
haveread
stays at 0, somaxlen
is not affected. If enough bytes were copied, the function returns immediately. If the first copy is partial,maxlen
is updated to reflect how much bytes should still be copied.