Skip to content

Commit

Permalink
Read all database attachments even if duplicated
Browse files Browse the repository at this point in the history
* Fixes #3048
* Certain programs that read/write KDBX4 files do not consolidate duplicate attachments into a single binary. This is against the KDBX4 specification. This change ensures KeePassXC will at least read the database in its entirety and not lose information. Upon saving the database in KeePassXC, the duplicate attachment binaries will be reduced to single binaries per the specification.
  • Loading branch information
droidmonkey committed May 25, 2019
1 parent 7ce6f9d commit 6d5c6c7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
22 changes: 3 additions & 19 deletions src/format/Kdbx4Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool Kdbx4Reader::readDatabaseImpl(QIODevice* device,
{
Q_ASSERT(m_kdbxVersion == KeePass2::FILE_VERSION_4);

m_binaryPoolInverse.clear();
m_binaryPool.clear();

if (hasError()) {
return false;
Expand Down Expand Up @@ -273,11 +273,7 @@ bool Kdbx4Reader::readInnerHeaderField(QIODevice* device)
return false;
}
auto data = fieldData.mid(1);
if (m_binaryPoolInverse.contains(data)) {
qWarning("Skipping duplicate binary record");
break;
}
m_binaryPoolInverse.insert(data, QString::number(m_binaryPoolInverse.size()));
m_binaryPool.insert(QString::number(m_binaryPool.size()), data);
break;
}
}
Expand Down Expand Up @@ -422,17 +418,5 @@ QVariantMap Kdbx4Reader::readVariantMap(QIODevice* device)
*/
QHash<QString, QByteArray> Kdbx4Reader::binaryPool() const
{
QHash<QString, QByteArray> binaryPool;
for (auto it = m_binaryPoolInverse.cbegin(); it != m_binaryPoolInverse.cend(); ++it) {
binaryPool.insert(it.value(), it.key());
}
return binaryPool;
}

/**
* @return mapping from binary data to attachment keys
*/
QHash<QByteArray, QString> Kdbx4Reader::binaryPoolInverse() const
{
return m_binaryPoolInverse;
return m_binaryPool;
}
3 changes: 1 addition & 2 deletions src/format/Kdbx4Reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class Kdbx4Reader : public KdbxReader
const QByteArray& headerData,
QSharedPointer<const CompositeKey> key,
Database* db) override;
QHash<QByteArray, QString> binaryPoolInverse() const;
QHash<QString, QByteArray> binaryPool() const;

protected:
Expand All @@ -44,7 +43,7 @@ class Kdbx4Reader : public KdbxReader
bool readInnerHeaderField(QIODevice* device);
QVariantMap readVariantMap(QIODevice* device);

QHash<QByteArray, QString> m_binaryPoolInverse;
QHash<QString, QByteArray> m_binaryPool;
};

#endif // KEEPASSX_KDBX4READER_H

0 comments on commit 6d5c6c7

Please sign in to comment.