Skip to content

Commit 3a85ca8

Browse files
committed
fix custom data lastModificationTime ignored during KDBX parse
Group and entry custom data items had their lastModificationTime values read but discarded during XML parsing. This caused merge conflict resolution in mergeCustomData() to always prefer incoming data regardless of timestamps.
1 parent 28f8f24 commit 3a85ca8

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

database/src/main/java/com/kunzisoft/keepass/database/file/input/DatabaseInputKDBX.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ class DatabaseInputKDBX(database: DatabaseKDBX)
9292
private var customDataLastModificationTime: DateInstant? = null
9393
private var groupCustomDataKey: String? = null
9494
private var groupCustomDataValue: String? = null
95+
private var groupCustomDataLastModificationTime: DateInstant? = null
9596
private var entryCustomDataKey: String? = null
9697
private var entryCustomDataValue: String? = null
98+
private var entryCustomDataLastModificationTime: DateInstant? = null
9799

98100
private var isRAMSufficient: (memoryWanted: Long) -> Boolean = {true}
99101

@@ -540,7 +542,7 @@ class DatabaseInputKDBX(database: DatabaseKDBX)
540542
KdbContext.GroupCustomDataItem -> when {
541543
name.equals(DatabaseKDBXXML.ElemKey, ignoreCase = true) -> groupCustomDataKey = readString(xpp)
542544
name.equals(DatabaseKDBXXML.ElemValue, ignoreCase = true) -> groupCustomDataValue = readString(xpp)
543-
name.equals(DatabaseKDBXXML.ElemLastModTime, ignoreCase = true) -> readDateInstant(xpp) // Ignore
545+
name.equals(DatabaseKDBXXML.ElemLastModTime, ignoreCase = true) -> groupCustomDataLastModificationTime = readDateInstant(xpp)
544546
else -> readUnknown(xpp)
545547
}
546548

@@ -592,7 +594,7 @@ class DatabaseInputKDBX(database: DatabaseKDBX)
592594
KdbContext.EntryCustomDataItem -> when {
593595
name.equals(DatabaseKDBXXML.ElemKey, ignoreCase = true) -> entryCustomDataKey = readString(xpp)
594596
name.equals(DatabaseKDBXXML.ElemValue, ignoreCase = true) -> entryCustomDataValue = readString(xpp)
595-
name.equals(DatabaseKDBXXML.ElemLastModTime, ignoreCase = true) -> readDateInstant(xpp) // Ignore
597+
name.equals(DatabaseKDBXXML.ElemLastModTime, ignoreCase = true) -> entryCustomDataLastModificationTime = readDateInstant(xpp)
596598
else -> readUnknown(xpp)
597599
}
598600

@@ -750,11 +752,12 @@ class DatabaseInputKDBX(database: DatabaseKDBX)
750752
} else if (ctx == KdbContext.GroupCustomDataItem && name.equals(DatabaseKDBXXML.ElemStringDictExItem, ignoreCase = true)) {
751753
groupCustomDataKey?.let { customDataKey ->
752754
groupCustomDataValue?.let { customDataValue ->
753-
ctxGroup?.customData?.put(CustomDataItem(customDataKey, customDataValue))
755+
ctxGroup?.customData?.put(CustomDataItem(customDataKey, customDataValue, groupCustomDataLastModificationTime))
754756
}
755757
}
756758
groupCustomDataKey = null
757759
groupCustomDataValue = null
760+
groupCustomDataLastModificationTime = null
758761
return KdbContext.GroupCustomData
759762

760763
} else if (ctx == KdbContext.Entry && name.equals(DatabaseKDBXXML.ElemEntry, ignoreCase = true)) {
@@ -802,11 +805,12 @@ class DatabaseInputKDBX(database: DatabaseKDBX)
802805
} else if (ctx == KdbContext.EntryCustomDataItem && name.equals(DatabaseKDBXXML.ElemStringDictExItem, ignoreCase = true)) {
803806
entryCustomDataKey?.let { customDataKey ->
804807
entryCustomDataValue?.let { customDataValue ->
805-
ctxEntry?.customData?.put(CustomDataItem(customDataKey, customDataValue))
808+
ctxEntry?.customData?.put(CustomDataItem(customDataKey, customDataValue, entryCustomDataLastModificationTime))
806809
}
807810
}
808811
entryCustomDataKey = null
809812
entryCustomDataValue = null
813+
entryCustomDataLastModificationTime = null
810814
return KdbContext.EntryCustomData
811815
} else if (ctx == KdbContext.EntryHistory && name.equals(DatabaseKDBXXML.ElemHistory, ignoreCase = true)) {
812816
entryInHistory = false

0 commit comments

Comments
 (0)