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)