Skip to content

Attachment handling: unused content kept, lookup by position, inline content, compression #118

Description

@jorabin

Found while fixing protected attachments for 3.1.2 (see BinaryProperties.md). In the KDBX implementation
(KdbxDatabase, KdbxEntry, KdbxSerializableDatabase):

  1. Unused attachment content is kept. Replacing an attachment (setBinaryProperty with an existing name)
    or removing one (removeBinaryProperty) removes the entry's reference, but the content stays in the binary
    pool (Meta/Binaries in KDBX 3.1, the inner header in KDBX 4) and is written on every save. KeePass drops
    pool items that nothing refers to (entries or their history) when it saves. As it is, files grow, and content
    the user removed is still in the file.

  2. Attachments are looked up both by ID and by position. Entries refer to pool items by ID (Ref), but
    SerializableDatabase.getBinary(index) and isBinaryProtected(index) use the position in the pool
    (the existing TODO in KdbxSerializableDatabase.getBinary). They agree for files that are read, where IDs are
    assigned in order, but nothing guarantees it, e.g. after fixing 1. Writing should renumber the pool and the
    references together.

  3. Inline attachment content isn't read. KeePass also reads an entry's <Binary><Value> holding the content
    itself (Base64, with Compressed or Protected), not a Ref into the pool, which some older files have.
    KeePassJava2 reads such an entry without its attachment.

  4. The database's compression setting isn't followed for attachments. Unprotected attachments in
    Meta/Binaries are always gzipped (Compressed="True") unless they were read uncompressed; KeePass compresses
    them only if the database uses compression. Every reader accepts either, so this is about matching KeePass.

Related, not about attachments: there's no way to choose the property value strategy when reading a database
(KdbxDatabase.read). Values read use the default strategy; a strategy set afterwards applies only to values
created later. This affects attachments too, from 3.1.2, since protected ones are held by the strategy's
protected factory.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions