mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Catch key file out of memory exception
This commit is contained in:
@@ -124,25 +124,29 @@ abstract class DatabaseVersioned<
|
|||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
protected fun getFileKey(keyInputStream: InputStream): ByteArray {
|
protected fun getFileKey(keyInputStream: InputStream): ByteArray {
|
||||||
val keyData = keyInputStream.readBytes()
|
try {
|
||||||
|
val keyData = keyInputStream.readBytes()
|
||||||
|
|
||||||
// Check XML key file
|
// Check XML key file
|
||||||
val xmlKeyByteArray = loadXmlKeyFile(ByteArrayInputStream(keyData))
|
val xmlKeyByteArray = loadXmlKeyFile(ByteArrayInputStream(keyData))
|
||||||
if (xmlKeyByteArray != null) {
|
if (xmlKeyByteArray != null) {
|
||||||
return xmlKeyByteArray
|
return xmlKeyByteArray
|
||||||
}
|
|
||||||
|
|
||||||
// Check 32 bytes key file
|
|
||||||
when (keyData.size) {
|
|
||||||
32 -> return keyData
|
|
||||||
64 -> try {
|
|
||||||
return Hex.decodeHex(String(keyData).toCharArray())
|
|
||||||
} catch (ignoredException: Exception) {
|
|
||||||
// Key is not base 64, treat it as binary data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check 32 bytes key file
|
||||||
|
when (keyData.size) {
|
||||||
|
32 -> return keyData
|
||||||
|
64 -> try {
|
||||||
|
return Hex.decodeHex(String(keyData).toCharArray())
|
||||||
|
} catch (ignoredException: Exception) {
|
||||||
|
// Key is not base 64, treat it as binary data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Hash file as binary data
|
||||||
|
return HashManager.hashSha256(keyData)
|
||||||
|
} catch (outOfMemoryError: OutOfMemoryError) {
|
||||||
|
throw IOException("Keyfile data is too large", outOfMemoryError)
|
||||||
}
|
}
|
||||||
// Hash file as binary data
|
|
||||||
return HashManager.hashSha256(keyData)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun loadXmlKeyFile(keyInputStream: InputStream): ByteArray? {
|
protected open fun loadXmlKeyFile(keyInputStream: InputStream): ByteArray? {
|
||||||
|
|||||||
Reference in New Issue
Block a user