From 2ac0179d65462b9947b145e568a2230aec4c706d Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Wed, 18 Apr 2018 21:20:06 -0700 Subject: [PATCH] Handle odd sized buffers on backup import decrypt Fixes #7701 --- .../securesms/backup/FullBackupImporter.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/backup/FullBackupImporter.java b/src/org/thoughtcrime/securesms/backup/FullBackupImporter.java index 138707b3ca..8f760467e3 100644 --- a/src/org/thoughtcrime/securesms/backup/FullBackupImporter.java +++ b/src/org/thoughtcrime/securesms/backup/FullBackupImporter.java @@ -204,11 +204,20 @@ public class FullBackupImporter extends FullBackupBase { mac.update(buffer, 0, read); byte[] plaintext = cipher.update(buffer, 0, read); - out.write(plaintext, 0, plaintext.length); + + if (plaintext != null) { + out.write(plaintext, 0, plaintext.length); + } length -= read; } + byte[] plaintext = cipher.doFinal(); + + if (plaintext != null) { + out.write(plaintext, 0, plaintext.length); + } + out.close(); byte[] ourMac = mac.doFinal(); @@ -225,7 +234,7 @@ public class FullBackupImporter extends FullBackupBase { //destination.delete(); throw new IOException("Bad MAC"); } - } catch (InvalidKeyException | InvalidAlgorithmParameterException e) { + } catch (InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException e) { throw new AssertionError(e); } }