From 4b3d1290971a8618d61fad735edb7de0f920de2d Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Sat, 19 Oct 2019 12:31:06 -0400 Subject: [PATCH] Cleanup some possible bad RecipientIds in the MMS table. --- .../database/helpers/SQLCipherOpenHelper.java | 10 +++++++++- .../securesms/recipients/RecipientId.java | 11 +++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java b/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java index d83a8d850e..867db0d96f 100644 --- a/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java +++ b/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java @@ -85,8 +85,9 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper { private static final int ATTACHMENT_HASHING = 28; private static final int NOTIFICATION_RECIPIENT_IDS = 29; private static final int BLUR_HASH = 30; + private static final int MMS_RECIPIENT_CLEANUP_2 = 31; - private static final int DATABASE_VERSION = 30; + private static final int DATABASE_VERSION = 31; private static final String DATABASE_NAME = "signal.db"; private final Context context; @@ -589,6 +590,13 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper { db.execSQL("ALTER TABLE part ADD COLUMN blur_hash TEXT DEFAULT NULL"); } + if (oldVersion < MMS_RECIPIENT_CLEANUP_2) { + ContentValues values = new ContentValues(1); + values.put("address", "-1"); + int count = db.update("mms", values, "address = ? OR address IS NULL", new String[] { "0" }); + Log.i(TAG, "MMS recipient cleanup 2 updated " + count + " rows."); + } + db.setTransactionSuccessful(); } finally { db.endTransaction(); diff --git a/src/org/thoughtcrime/securesms/recipients/RecipientId.java b/src/org/thoughtcrime/securesms/recipients/RecipientId.java index cc0496489a..ffa72b1e73 100644 --- a/src/org/thoughtcrime/securesms/recipients/RecipientId.java +++ b/src/org/thoughtcrime/securesms/recipients/RecipientId.java @@ -24,14 +24,18 @@ public class RecipientId implements Parcelable, Comparable { public static RecipientId from(long id) { if (id == 0) { - throw new AssertionError("Invalid ID!"); + throw new InvalidLongRecipientIdError(); } return new RecipientId(id); } public static RecipientId from(@NonNull String id) { - return RecipientId.from(Long.parseLong(id)); + try { + return RecipientId.from(Long.parseLong(id)); + } catch (NumberFormatException e) { + throw new InvalidStringRecipientIdError(); + } } private RecipientId(long id) { @@ -116,4 +120,7 @@ public class RecipientId implements Parcelable, Comparable { return new RecipientId[size]; } }; + + private static class InvalidLongRecipientIdError extends AssertionError {} + private static class InvalidStringRecipientIdError extends AssertionError {} }