Skip to content

Commit

Permalink
Fix invalid attachment data during sms export.
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-signal authored and greyson-signal committed Feb 15, 2023
1 parent c75a9b5 commit 2b0e978
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5300,6 +5300,10 @@ public MessageRecord getCurrent() {
}
}

public MessageId getCurrentId() {
return new MessageId(CursorUtil.requireLong(cursor, ID));
}

@Override
public @NonNull MessageExportState getMessageExportStateForCurrentRecord() {
byte[] messageExportState = CursorUtil.requireBlob(cursor, MessageTable.EXPORT_STATE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.thoughtcrime.securesms.exporter

import org.json.JSONException
import org.signal.core.util.logging.Log
import org.signal.smsexporter.ExportableMessage
import org.signal.smsexporter.SmsExportState
Expand Down Expand Up @@ -92,6 +93,11 @@ class SignalSmsExportReader(
throw NoSuchElementException()
}
} catch (e: Throwable) {
if (e.cause is JSONException) {
Log.w(TAG, "Error processing attachment json, skipping message.", e)
return ExportableMessage.Skip(messageReader!!.currentId)
}

Log.w(TAG, "Error processing message: isMms: ${record?.isMms} type: ${record?.type}")
throw e
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class SignalSmsExportService : SmsExportService() {
val messageId: Any = when (this) {
is ExportableMessage.Mms<*> -> id
is ExportableMessage.Sms<*> -> id
is ExportableMessage.Skip<*> -> id
}

if (messageId is MessageId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ sealed interface ExportableMessage {
}
}
}

data class Skip<out ID : Any>(
val id: ID,
override val exportState: SmsExportState = SmsExportState()
) : ExportableMessage
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ abstract class SmsExportService : Service() {
val successful = when (message) {
is ExportableMessage.Sms<*> -> exportSms(exportState, message)
is ExportableMessage.Mms<*> -> exportMms(exportState, message)
is ExportableMessage.Skip<*> -> {
onMessageExportSucceeded(message)
true
}
}

if (!successful) {
Expand Down

0 comments on commit 2b0e978

Please sign in to comment.