Fix binaries unique Ids #713

This commit is contained in:
J-Jamet
2020-09-23 17:07:15 +02:00
parent a45d114527
commit 920764ad33
2 changed files with 10 additions and 2 deletions

View File

@@ -107,6 +107,7 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
val customData = HashMap<String, String>()
var binaryPool = BinaryPool()
private var binaryIncrement = 0 // Unique id (don't use current time because CPU too fast)
var localizedAppName = "KeePassDX"
@@ -561,7 +562,8 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
compression: Boolean,
binaryPoolId: Int? = null): BinaryAttachment {
// New file with current time
val fileInCache = File(cacheDirectory, System.currentTimeMillis().toString())
val fileInCache = File(cacheDirectory, binaryIncrement.toString())
binaryIncrement++
val binaryAttachment = BinaryAttachment(fileInCache, protection, compression)
// add attachment to pool
binaryPool.put(binaryPoolId, binaryAttachment)

View File

@@ -954,7 +954,13 @@ class DatabaseInputKDBX(cacheDirectory: File,
xpp.next() // Consume end tag
val id = Integer.parseInt(ref)
// A ref is not necessarily an index in Database V3.1
mDatabase.binaryPool[id]
var binaryRetrieve = mDatabase.binaryPool[id]
// Create empty binary if not retrieved in pool
if (binaryRetrieve == null) {
binaryRetrieve = mDatabase.buildNewBinary(cacheDirectory,
protection = false, compression = false, binaryPoolId = id)
}
return binaryRetrieve
}
key != null -> {
createBinary(key.toIntOrNull(), xpp)