Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] WriteFileAsync will not reduce file size resuling in data leak (SFTP) #52

Closed
beeradmoore opened this issue Jan 30, 2024 · 2 comments
Labels
bug Something isn't working SFTP

Comments

@beeradmoore
Copy link
Contributor

beeradmoore commented Jan 30, 2024

If you have a file locally that contains the following text

12345678

and you upload that file with await myRemoteStorage.WriteFileAsync(myRemoteFile, myLocalFile) you will create a file at myRemoteFile and it will be 8 bytes long.

If you now change the file locally to be

0000

and call await myRemoteStorage.WriteFileAsync(myRemoteFile, myLocalFile) then the result file on the server will not change its filesize and it will actually contain the text

00005678

I believe this comes from the WriteAsync method which opens a local and remote stream (see FluentFtpBlobStorage and SshNetSftpBlobStorage) and calls CopyAsync. This does exactly that, copies the stream of data across. But after the rest of the file is not removed.

This is very similar to the behaviour which casued people to be able to uncrop screenshots due to a bug in the image cropper.

Using UploadFile from the respective clients should solve this problem, but it prevents being able to append to a file.

I'll try it out and see how it goes, if I find a solution I'll create a PR.

Provider Impacted (may not be accurate)
FluentStorage
FluentStorage.AWS
FluentStorage.GCP
FluentStorage.Databricks
FluentStorage.FTP
FluentStorage.SFTP
FluentStorage.Azure.Blobs
FluentStorage.Azure.Files
FluentStorage.Azure.EventHub
FluentStorage.Azure.ServiceBus
FluentStorage.Azure.KeyVault
FluentStorage.Azure.ServiceFabric
FluentStorage.Azure.Queues
FluentStorage.Azure.DataLake

Skimming through code to see what is and isn't impacted. May not be 100% accurate. (EDIT: Tested FluentStorage.FTP thismroning and it does not have this problem)

Eyeballing the test here (without actuallying knowing how these tests work), changing the attributes to have something smaller after the longer test should find it? (assuming upload to the same location)

[InlineData("sample")]
[InlineData("123")]
[InlineData("123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123")]
[InlineData("456")]
@beeradmoore beeradmoore changed the title [Bug] WriteFileAsync will not reduce file size resuling in data leak (tested with FTP and SFTP) [Bug] WriteFileAsync will not reduce file size resuling in data leak (SFTP) Jan 30, 2024
@beeradmoore
Copy link
Contributor Author

Upon testing today I was not able to replicate in FluentStorage.FTP. I guess the underlying FtpDataStream object handles this correctly and the issue may only be with how SftpFileStream handles things.

It appears adding a .SetLength( fixes the issue.

@robinrodricks
Copy link
Owner

Fixed by OP.

@robinrodricks robinrodricks added bug Something isn't working SFTP labels Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SFTP
Projects
None yet
Development

No branches or pull requests

2 participants