From 6d5c6c7d17def8419cfe273c76b9f91a5020fd5b Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Sat, 25 May 2019 09:13:43 -0400 Subject: [PATCH] Read all database attachments even if duplicated * 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. --- src/format/Kdbx4Reader.cpp | 22 +++------------------- src/format/Kdbx4Reader.h | 3 +-- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/format/Kdbx4Reader.cpp b/src/format/Kdbx4Reader.cpp index 4bb0202b1..d0914a04e 100644 --- a/src/format/Kdbx4Reader.cpp +++ b/src/format/Kdbx4Reader.cpp @@ -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; @@ -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; } } @@ -422,17 +418,5 @@ QVariantMap Kdbx4Reader::readVariantMap(QIODevice* device) */ QHash Kdbx4Reader::binaryPool() const { - QHash 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 Kdbx4Reader::binaryPoolInverse() const -{ - return m_binaryPoolInverse; + return m_binaryPool; } diff --git a/src/format/Kdbx4Reader.h b/src/format/Kdbx4Reader.h index 3afb5bf69..fc73a1fbd 100644 --- a/src/format/Kdbx4Reader.h +++ b/src/format/Kdbx4Reader.h @@ -34,7 +34,6 @@ public: const QByteArray& headerData, QSharedPointer key, Database* db) override; - QHash binaryPoolInverse() const; QHash binaryPool() const; protected: @@ -44,7 +43,7 @@ private: bool readInnerHeaderField(QIODevice* device); QVariantMap readVariantMap(QIODevice* device); - QHash m_binaryPoolInverse; + QHash m_binaryPool; }; #endif // KEEPASSX_KDBX4READER_H