Repository navigation
fix(files_external): incorrect content when copying files on SFTP storage - #66672
Draft
joshtrichards wants to merge 3 commits into
Draft
joshtrichards wants to merge 3 commits into
joshtrichards wants to merge 3 commits into
Conversation
Previously: - Copying a shorter file over an existing file left old trailing bytes. - Copying an empty file over an existing file reported success but left the destination untouched. - Copying an empty file to a new location reported success but created nothing. - A failed overwrite could leave new content mixed with old content. Changes: - Write the first chunk without an explicit offset so phpseclib truncates an existing destination before writing. - Write an empty string for empty sources, creating or truncating the destination and reporting write failures. - Avoid truncating the source when the normalized paths match. This does not detect aliases such as symlinks or hard links. A failed copy can still leave a partial destination, but it will no longer be mixed with old trailing bytes. The overall copy() operation also remains non-atomic. Assisted-by: Copilot:gpt-6.1-terra Signed-off-by: Josh <josh.t.richards@gmail.com>
Exercise copies around chunk boundaries and verify the resulting destination contents and transfer offsets. Cover unavailable source sizes, read and write failures on the first and later chunks, and failure to write an empty destination. Add integration cases for overwrites, empty files, and self-copy. Assisted-by: Copilot:gpt-6.1-terra Signed-off-by: Josh <josh.t.richards@gmail.com>
phpseclib's get() can return a string shorter than requested, including an empty string, when it reaches EOF or receives an SFTP status response. The current loop accepts these reads, writes the returned data, and advances by a full chunk. It can therefore report success with incomplete content. Request and verify the expected remaining length for each chunk, accounting for the final chunk being smaller than COPY_CHUNK_SIZE. This also reports failure if the source shrinks during copying. It does not guarantee a consistent snapshot if the source changes without changing size, and failure after an earlier write can leave a partial destination. The check is inexpensive and prevents silent success in the noted cases. This has been around since #40183. I was surprised I couldn't find any relevant bug reports, but only same-mount copies use this path and ordinary non-empty copies to new filenames work, so much routine copying wouldn’t expose either bug. Assisted-by: Copilot:gpt-6.1-sol Signed-off-by: Josh <josh.t.richards@gmail.com>
Contributor
|
Possible performance regression detected Show Output |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Previously:
Changes:
SFTP::copy().A failed copy can still leave a partial destination, but it will no longer be mixed with old trailing bytes. The overall copy() operation also remains non-atomic.
These have been around since #40183. I was surprised I couldn't find any relevant bug reports, but only same-mount copies use this path and ordinary non-empty copies to new filenames work, so much routine copying wouldn’t expose either bug.
TODO
Checklist
3. to review, feature component)stable32)AI (if applicable)