Skip attachments with unrecoverable errors during sms export.
This commit is contained in:
parent
57e8684bb3
commit
10e8c6d795
3 changed files with 23 additions and 4 deletions
|
@ -22,6 +22,8 @@ import javax.crypto.spec.SecretKeySpec;
|
||||||
|
|
||||||
public class ModernDecryptingPartInputStream {
|
public class ModernDecryptingPartInputStream {
|
||||||
|
|
||||||
|
public static final String PREMATURE_END_ERROR_MESSAGE = "Prematurely reached end of stream!";
|
||||||
|
|
||||||
public static InputStream createFor(@NonNull AttachmentSecret attachmentSecret, @NonNull byte[] random, @NonNull File file, long offset)
|
public static InputStream createFor(@NonNull AttachmentSecret attachmentSecret, @NonNull byte[] random, @NonNull File file, long offset)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
|
@ -75,7 +77,7 @@ public class ModernDecryptingPartInputStream {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int read = in.read(buffer, offset, buffer.length-offset);
|
int read = in.read(buffer, offset, buffer.length-offset);
|
||||||
|
|
||||||
if (read == -1) throw new IOException("Prematurely reached end of stream!");
|
if (read == -1) throw new IOException(PREMATURE_END_ERROR_MESSAGE);
|
||||||
else if (read + offset < buffer.length) offset += read;
|
else if (read + offset < buffer.length) offset += read;
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.signal.smsexporter.ExportableMessage
|
||||||
import org.signal.smsexporter.SmsExportService
|
import org.signal.smsexporter.SmsExportService
|
||||||
import org.thoughtcrime.securesms.R
|
import org.thoughtcrime.securesms.R
|
||||||
import org.thoughtcrime.securesms.attachments.AttachmentId
|
import org.thoughtcrime.securesms.attachments.AttachmentId
|
||||||
|
import org.thoughtcrime.securesms.crypto.ModernDecryptingPartInputStream
|
||||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||||
import org.thoughtcrime.securesms.database.model.MessageId
|
import org.thoughtcrime.securesms.database.model.MessageId
|
||||||
import org.thoughtcrime.securesms.database.model.databaseprotos.MessageExportState
|
import org.thoughtcrime.securesms.database.model.databaseprotos.MessageExportState
|
||||||
|
@ -19,6 +20,7 @@ import org.thoughtcrime.securesms.notifications.NotificationChannels
|
||||||
import org.thoughtcrime.securesms.notifications.NotificationIds
|
import org.thoughtcrime.securesms.notifications.NotificationIds
|
||||||
import org.thoughtcrime.securesms.notifications.v2.NotificationPendingIntentHelper
|
import org.thoughtcrime.securesms.notifications.v2.NotificationPendingIntentHelper
|
||||||
import org.thoughtcrime.securesms.util.JsonUtils
|
import org.thoughtcrime.securesms.util.JsonUtils
|
||||||
|
import java.io.EOFException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
|
@ -168,7 +170,15 @@ class SignalSmsExportService : SmsExportService() {
|
||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun getInputStream(part: ExportableMessage.Mms.Part): InputStream {
|
override fun getInputStream(part: ExportableMessage.Mms.Part): InputStream {
|
||||||
return SignalDatabase.attachments.getAttachmentStream(JsonUtils.fromJson(part.contentId, AttachmentId::class.java), 0)
|
try {
|
||||||
|
return SignalDatabase.attachments.getAttachmentStream(JsonUtils.fromJson(part.contentId, AttachmentId::class.java), 0)
|
||||||
|
} catch (e: IOException) {
|
||||||
|
if (e.message == ModernDecryptingPartInputStream.PREMATURE_END_ERROR_MESSAGE) {
|
||||||
|
throw EOFException(e.message)
|
||||||
|
} else {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onExportPassCompleted() {
|
override fun onExportPassCompleted() {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import org.signal.smsexporter.internal.mms.ExportMmsPartsUseCase
|
||||||
import org.signal.smsexporter.internal.mms.ExportMmsRecipientsUseCase
|
import org.signal.smsexporter.internal.mms.ExportMmsRecipientsUseCase
|
||||||
import org.signal.smsexporter.internal.mms.GetOrCreateMmsThreadIdsUseCase
|
import org.signal.smsexporter.internal.mms.GetOrCreateMmsThreadIdsUseCase
|
||||||
import org.signal.smsexporter.internal.sms.ExportSmsMessagesUseCase
|
import org.signal.smsexporter.internal.sms.ExportSmsMessagesUseCase
|
||||||
|
import java.io.EOFException
|
||||||
import java.io.FileNotFoundException
|
import java.io.FileNotFoundException
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.util.concurrent.Executor
|
import java.util.concurrent.Executor
|
||||||
|
@ -346,8 +347,14 @@ abstract class SmsExportService : Service() {
|
||||||
onAttachmentPartExportSucceeded(output.message, output.part)
|
onAttachmentPartExportSucceeded(output.message, output.part)
|
||||||
Try.success(Unit)
|
Try.success(Unit)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.d(TAG, "Failed to write attachment to disk.", e)
|
if (e is EOFException) {
|
||||||
Try.failure(e)
|
Log.d(TAG, "Unrecoverable failure to write attachment to disk, marking as successful and moving on", e)
|
||||||
|
onAttachmentPartExportSucceeded(output.message, output.part)
|
||||||
|
Try.success(Unit)
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "Failed to write attachment to disk.", e)
|
||||||
|
Try.failure(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue