From 920764ad330f9fbc62fdff1f646d3e2682f2dc64 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Wed, 23 Sep 2020 17:07:15 +0200 Subject: [PATCH] Fix binaries unique Ids #713 --- .../keepass/database/element/database/DatabaseKDBX.kt | 4 +++- .../keepass/database/file/input/DatabaseInputKDBX.kt | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/kunzisoft/keepass/database/element/database/DatabaseKDBX.kt b/app/src/main/java/com/kunzisoft/keepass/database/element/database/DatabaseKDBX.kt index baadf38e9..b18ae74a9 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/element/database/DatabaseKDBX.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/element/database/DatabaseKDBX.kt @@ -107,6 +107,7 @@ class DatabaseKDBX : DatabaseVersioned { val customData = HashMap() 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 { 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) diff --git a/app/src/main/java/com/kunzisoft/keepass/database/file/input/DatabaseInputKDBX.kt b/app/src/main/java/com/kunzisoft/keepass/database/file/input/DatabaseInputKDBX.kt index e234f7a4c..f695d4186 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/file/input/DatabaseInputKDBX.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/file/input/DatabaseInputKDBX.kt @@ -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)