PhilippC / PhilippC/keepass2android

[BUG] FTP save produces truncated/corrupt KDBX file – file gets smaller when adding entries

Open
#3,188 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
6.2k
Forks
478
Avg merge
1h 4m
Merged PRs (30d)
2

Description

Checks
  • 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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in CachingFileStorage.cs at UpdateRemoteFile and in NetFtpFileStorage.cs at TransactedWrite.CommitWrite and UntransactedWrite.CommitWrite. Review how each FTP stream is closed, then verify that the full database upload completes before the stream is closed and that the resulting KDBX file is no longer truncated.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
mobile, networking
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.