From 42cdb1db1146a65d8a270eb23e5aac29e73edda8 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 17 Dec 2019 12:26:45 +0100 Subject: [PATCH] Fix crash reported by rageshake: writeToFile may throw exceptions --- .../android/internal/session/DefaultFileService.kt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultFileService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultFileService.kt index 868d63665a..c160ac9b31 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultFileService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultFileService.kt @@ -83,15 +83,13 @@ internal class DefaultFileService @Inject constructor(private val context: Conte if (elementToDecrypt != null) { Timber.v("## decrypt file") - MXEncryptedAttachments.decryptAttachment(inputStream, elementToDecrypt) ?: throw IllegalStateException("Decryption error") - } else { - inputStream + MXEncryptedAttachments.decryptAttachment(inputStream, elementToDecrypt) + ?: throw IllegalStateException("Decryption error") } + + writeToFile(inputStream, destFile) + destFile } - .map { inputStream -> - writeToFile(inputStream, destFile) - destFile - } } else { Try.just(destFile) }