mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 07:28:34 +00:00
Skip corrupt attachments during backup restore.
Instead of aborting the entire backup restore. Related to #8355
This commit is contained in:
parent
e574c81ea2
commit
17b5816d5b
@ -130,15 +130,23 @@ public class FullBackupImporter extends FullBackupBase {
|
|||||||
{
|
{
|
||||||
File partsDirectory = context.getDir(AttachmentDatabase.DIRECTORY, Context.MODE_PRIVATE);
|
File partsDirectory = context.getDir(AttachmentDatabase.DIRECTORY, Context.MODE_PRIVATE);
|
||||||
File dataFile = File.createTempFile("part", ".mms", partsDirectory);
|
File dataFile = File.createTempFile("part", ".mms", partsDirectory);
|
||||||
|
|
||||||
Pair<byte[], OutputStream> output = ModernEncryptingPartOutputStream.createFor(attachmentSecret, dataFile, false);
|
Pair<byte[], OutputStream> output = ModernEncryptingPartOutputStream.createFor(attachmentSecret, dataFile, false);
|
||||||
|
|
||||||
|
ContentValues contentValues = new ContentValues();
|
||||||
|
|
||||||
|
try {
|
||||||
inputStream.readAttachmentTo(output.second, attachment.getLength());
|
inputStream.readAttachmentTo(output.second, attachment.getLength());
|
||||||
|
|
||||||
ContentValues contentValues = new ContentValues();
|
|
||||||
contentValues.put(AttachmentDatabase.DATA, dataFile.getAbsolutePath());
|
contentValues.put(AttachmentDatabase.DATA, dataFile.getAbsolutePath());
|
||||||
contentValues.put(AttachmentDatabase.THUMBNAIL, (String)null);
|
contentValues.put(AttachmentDatabase.THUMBNAIL, (String)null);
|
||||||
contentValues.put(AttachmentDatabase.DATA_RANDOM, output.first);
|
contentValues.put(AttachmentDatabase.DATA_RANDOM, output.first);
|
||||||
|
} catch (BadMacException e) {
|
||||||
|
Log.w(TAG, "Bad MAC for attachment " + attachment.getAttachmentId() + "! Can't restore it.", e);
|
||||||
|
dataFile.delete();
|
||||||
|
contentValues.put(AttachmentDatabase.DATA, (String) null);
|
||||||
|
contentValues.put(AttachmentDatabase.THUMBNAIL, (String) null);
|
||||||
|
contentValues.put(AttachmentDatabase.DATA_RANDOM, (String) null);
|
||||||
|
}
|
||||||
|
|
||||||
db.update(AttachmentDatabase.TABLE_NAME, contentValues,
|
db.update(AttachmentDatabase.TABLE_NAME, contentValues,
|
||||||
AttachmentDatabase.ROW_ID + " = ? AND " + AttachmentDatabase.UNIQUE_ID + " = ?",
|
AttachmentDatabase.ROW_ID + " = ? AND " + AttachmentDatabase.UNIQUE_ID + " = ?",
|
||||||
@ -285,13 +293,11 @@ public class FullBackupImporter extends FullBackupBase {
|
|||||||
try {
|
try {
|
||||||
Util.readFully(in, theirMac);
|
Util.readFully(in, theirMac);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
//destination.delete();
|
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!MessageDigest.isEqual(ourMac, theirMac)) {
|
if (!MessageDigest.isEqual(ourMac, theirMac)) {
|
||||||
//destination.delete();
|
throw new BadMacException();
|
||||||
throw new IOException("Bad MAC");
|
|
||||||
}
|
}
|
||||||
} catch (InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException e) {
|
} catch (InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
@ -328,6 +334,8 @@ public class FullBackupImporter extends FullBackupBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class BadMacException extends IOException {}
|
||||||
|
|
||||||
public static class DatabaseDowngradeException extends IOException {
|
public static class DatabaseDowngradeException extends IOException {
|
||||||
DatabaseDowngradeException(int currentVersion, int backupVersion) {
|
DatabaseDowngradeException(int currentVersion, int backupVersion) {
|
||||||
super("Tried to import a backup with version " + backupVersion + " into a database with version " + currentVersion);
|
super("Tried to import a backup with version " + backupVersion + " into a database with version " + currentVersion);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user