Fix validation errors around bad e164s in SSE's and merge events.

This commit is contained in:
Greyson Parrelli
2025-05-27 10:29:13 -04:00
parent 5009e86d56
commit 7c04b56a32
2 changed files with 24 additions and 11 deletions

View File

@@ -111,6 +111,14 @@ object ExportSkips {
return log(sentTimestamp, "Learned profile update was empty.") return log(sentTimestamp, "Learned profile update was empty.")
} }
fun invalidE164InThreadMerge(sentTimestamp: Long): String {
return log(sentTimestamp, "Invalid e164 in thread merge event.")
}
fun failedToParseThreadMergeEvent(sentTimestamp: Long): String {
return log(sentTimestamp, "Failed to parse thread merge event.")
}
private fun log(sentTimestamp: Long, message: String): String { private fun log(sentTimestamp: Long, message: String): String {
return "[SKIP][$sentTimestamp] $message" return "[SKIP][$sentTimestamp] $message"
} }
@@ -158,6 +166,10 @@ object ExportOddities {
return log(sentTimestamp, "Quote had no text or attachments. Removing it.") return log(sentTimestamp, "Quote had no text or attachments. Removing it.")
} }
fun invalidE164InSessionSwitchover(sentTimestamp: Long): String {
return log(sentTimestamp, "Invalid e164 in sessions switchover event. Exporting an empty event.")
}
private fun log(sentTimestamp: Long, message: String): String { private fun log(sentTimestamp: Long, message: String): String {
return "[ODDITY][$sentTimestamp] $message" return "[ODDITY][$sentTimestamp] $message"
} }

View File

@@ -16,6 +16,7 @@ import org.signal.core.util.ParallelEventTimer
import org.signal.core.util.concurrent.SignalExecutors import org.signal.core.util.concurrent.SignalExecutors
import org.signal.core.util.isNotNullOrBlank import org.signal.core.util.isNotNullOrBlank
import org.signal.core.util.logging.Log import org.signal.core.util.logging.Log
import org.signal.core.util.logging.logW
import org.signal.core.util.nullIfBlank import org.signal.core.util.nullIfBlank
import org.signal.core.util.nullIfEmpty import org.signal.core.util.nullIfEmpty
import org.signal.core.util.orNull import org.signal.core.util.orNull
@@ -286,12 +287,12 @@ class ChatItemArchiveExporter(
} }
MessageTypes.isSessionSwitchoverType(record.type) -> { MessageTypes.isSessionSwitchoverType(record.type) -> {
builder.updateMessage = record.toRemoteSessionSwitchoverUpdate() builder.updateMessage = record.toRemoteSessionSwitchoverUpdate(record.dateSent)
transformTimer.emit("sse") transformTimer.emit("sse")
} }
MessageTypes.isThreadMergeType(record.type) -> { MessageTypes.isThreadMergeType(record.type) -> {
builder.updateMessage = record.toRemoteThreadMergeUpdate()?.takeIf { exportState.recipientIdToAci.contains(builder.authorId) } ?: continue builder.updateMessage = record.toRemoteThreadMergeUpdate(record.dateSent)?.takeIf { exportState.recipientIdToAci.contains(builder.authorId) } ?: continue
transformTimer.emit("thread-merge") transformTimer.emit("thread-merge")
} }
@@ -605,7 +606,7 @@ private fun BackupMessageRecord.toRemoteProfileChangeUpdate(): ChatUpdateMessage
} }
} }
private fun BackupMessageRecord.toRemoteSessionSwitchoverUpdate(): ChatUpdateMessage { private fun BackupMessageRecord.toRemoteSessionSwitchoverUpdate(sentTimestamp: Long): ChatUpdateMessage {
if (this.body == null) { if (this.body == null) {
return ChatUpdateMessage(sessionSwitchover = SessionSwitchoverChatUpdate()) return ChatUpdateMessage(sessionSwitchover = SessionSwitchoverChatUpdate())
} }
@@ -613,27 +614,27 @@ private fun BackupMessageRecord.toRemoteSessionSwitchoverUpdate(): ChatUpdateMes
return ChatUpdateMessage( return ChatUpdateMessage(
sessionSwitchover = try { sessionSwitchover = try {
val event = SessionSwitchoverEvent.ADAPTER.decode(Base64.decodeOrThrow(this.body)) val event = SessionSwitchoverEvent.ADAPTER.decode(Base64.decodeOrThrow(this.body))
SessionSwitchoverChatUpdate(event.e164.e164ToLong() ?: 0) val e164 = event.e164.e164ToLong() ?: return ChatUpdateMessage(sessionSwitchover = SessionSwitchoverChatUpdate()).logW(TAG, ExportOddities.invalidE164InSessionSwitchover(sentTimestamp))
SessionSwitchoverChatUpdate(e164)
} catch (e: IOException) { } catch (e: IOException) {
SessionSwitchoverChatUpdate() SessionSwitchoverChatUpdate()
} }
) )
} }
private fun BackupMessageRecord.toRemoteThreadMergeUpdate(): ChatUpdateMessage? { private fun BackupMessageRecord.toRemoteThreadMergeUpdate(sentTimestamp: Long): ChatUpdateMessage? {
if (this.body == null) { if (this.body == null) {
return null return null
} }
try { try {
val e164 = ThreadMergeEvent.ADAPTER.decode(Base64.decodeOrThrow(this.body)).previousE164.e164ToLong() val event = ThreadMergeEvent.ADAPTER.decode(Base64.decodeOrThrow(this.body))
if (e164 != null) { val e164 = event.previousE164.e164ToLong() ?: return null.logW(TAG, ExportSkips.invalidE164InThreadMerge(sentTimestamp))
return ChatUpdateMessage(threadMerge = ThreadMergeChatUpdate(e164)) return ChatUpdateMessage(threadMerge = ThreadMergeChatUpdate(e164))
}
} catch (_: IOException) { } catch (_: IOException) {
Log.w(TAG, ExportSkips.failedToParseThreadMergeEvent(sentTimestamp))
return null
} }
return null
} }
private fun BackupMessageRecord.toRemoteGroupUpdate(): ChatUpdateMessage? { private fun BackupMessageRecord.toRemoteGroupUpdate(): ChatUpdateMessage? {