[BUG] FTP save produces truncated/corrupt KDBX file – file gets smaller when adding entries
Checks
- [x] I have read the FAQ section, searched the open issues, and still think this is a new bug.
Describe the bug you encountered:
Description: When saving the database to FTP after adding a new entry on the device, the uploaded file is truncated/corrupt. The file on the FTP server becomes smaller instead of larger. KeePassXC fails to open it with "Ungültige Größe der Inner-Header-ID" (Invalid inner header id size).
Expected behavior: The full database is uploaded; file size increases when adding data.
Actual behavior: Uploaded file is smaller and unreadable by KeePassXC.
Analysis (from code review):
In CachingFileStorage.cs (UpdateRemoteFile) and NetFtpFileStorage.cs (TransactedWrite.CommitWrite, UntransactedWrite.CommitWrite), the FTP upload stream is closed without calling Flush() first. FTP streams can buffer data; without Flush(), the transfer may complete before all buffered data is sent, resulting in a truncated file.
Suggested fix:
Add remoteStream.Flush() before remoteStream.Close() in:
- CachingFileStorage.cs line 364
- NetFtpFileStorage.cs TransactedWrite.CommitWrite (before _stream.Close())
- NetFtpFileStorage.cs UntransactedWrite.CommitWrite (before _stream.Close())
Environment: Android, FTP (Kasserver), KeePass2Android latest
References: Similar issue with FluentFTP OpenWrite: https://stackoverflow.com/questions/35558561/system-net-ftpclient-openwrite-doesnt-upload-file-unless-i-insert-a-sleep-before
Describe what you expected to happen:
No response
What version of Keepass2Android are you using?
1.14-r4
Which version of Android are you on?
16