Signal-Android icon indicating copy to clipboard operation
Signal-Android copied to clipboard

[4.17.0] Restore of message with embedded quote crashes

Open sesse opened this issue 8 years ago • 5 comments

Hi,

I just did a backup with 4.17.0 on one phone, trying to import it to the other one. (You need to have the backup before starting Signal the first time, though—just delaying registering doesn't help, which is confusing.)

Signal promptly crashed. It turned out (from adb logcat) that it fails to escape messages correctly in SQL:

03-09 23:30:45.901  2986  3441 E AndroidRuntime: FATAL EXCEPTION: AsyncTask #5
03-09 23:30:45.901  2986  3441 E AndroidRuntime: Process: org.thoughtcrime.securesms, PID: 2986
03-09 23:30:45.901  2986  3441 E AndroidRuntime: java.lang.RuntimeException: An error occurred while executing doInBackground()
03-09 23:30:45.901  2986  3441 E AndroidRuntime: 	at android.os.AsyncTask$3.done(AsyncTask.java:353)
03-09 23:30:45.901  2986  3441 E AndroidRuntime: 	at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
03-09 23:30:45.901  2986  3441 E AndroidRuntime: 	at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
03-09 23:30:45.901  2986  3441 E AndroidRuntime: 	at java.util.concurrent.FutureTask.run(FutureTask.java:271)
03-09 23:30:45.901  2986  3441 E AndroidRuntime: 	at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
03-09 23:30:45.901  2986  3441 E AndroidRuntime: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
03-09 23:30:45.901  2986  3441 E AndroidRuntime: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
03-09 23:30:45.901  2986  3441 E AndroidRuntime: 	at java.lang.Thread.run(Thread.java:764)
03-09 23:30:45.901  2986  3441 E AndroidRuntime: Caused by: net.sqlcipher.database.SQLiteException: near "nye": syntax error: INSERT INTO sms VALUES (19,2,'<censored>',1,NULL,1454911174668,1454911174668,NULL,1,-1,23,NULL,0,NULL,'<censored>',NULL,NULL,-1,0,0,0,0)
03-09 23:30:45.901  2986  3441 E AndroidRuntime: 	at net.sqlcipher.database.SQLiteDatabase.native_execSQL(Native Method)
03-09 23:30:45.901  2986  3441 E AndroidRuntime: 	at net.sqlcipher.database.SQLiteDatabase.execSQL(SQLiteDatabase.java:2265)
03-09 23:30:45.901  2986  3441 E AndroidRuntime: 	at org.thoughtcrime.securesms.backup.FullBackupImporter.processStatement(FullBackupImporter.java:85)
03-09 23:30:45.901  2986  3441 E AndroidRuntime: 	at org.thoughtcrime.securesms.backup.FullBackupImporter.importFile(FullBackupImporter.java:67)
03-09 23:30:45.901  2986  3441 E AndroidRuntime: 	at org.thoughtcrime.securesms.RegistrationActivity$2.doInBackground(RegistrationActivity.java:367)
03-09 23:30:45.901  2986  3441 E AndroidRuntime: 	at org.thoughtcrime.securesms.RegistrationActivity$2.doInBackground(RegistrationActivity.java:359)
03-09 23:30:45.901  2986  3441 E AndroidRuntime: 	at android.os.AsyncTask$2.call(AsyncTask.java:333)
03-09 23:30:45.901  2986  3441 E AndroidRuntime: 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
03-09 23:30:45.901  2986  3441 E AndroidRuntime: 	... 4 more

I've censored the message itself, but it contained the string “SAS' nye”, so it is reasonable to believe that the problem is the embedded quote.

sesse avatar Mar 09 '18 22:03 sesse

duplicate #7478 thanks

moxie0 avatar Mar 09 '18 22:03 moxie0

FWIW: There was an update from Play Store today, but the exact same problem remains. I'll just assume the commit didn't make this one.

sesse avatar Mar 10 '18 21:03 sesse

The fix is in creating the backup, not restoring it. So old backups still won't restore, but newly created ones will.

moxie0 avatar Mar 10 '18 22:03 moxie0

I took a new backup and tried to restore it, but alas:

03-11 01:07:08.325 24981 25167 E AndroidRuntime: Caused by: net.sqlcipher.database.SQLiteException: near "nye": syntax error: INSERT INTO sms VALUES (19,2,'<censored>',1,NULL,1454911174668,1454911174668,NULL,1,-1,23,NULL,0,NULL,'<censored> SAS\' nye <censored>',NULL,NULL,-1,0,0,0,0)

Seemingly the correct way to escape a quote in SQLite is to double it, not add a backslash.

sesse avatar Mar 11 '18 00:03 sesse

I also just took a new backup with 4.17.1, attempted to restore with 4.17.1, and the same SQL exception with the quotes occurred.

junitas avatar Mar 11 '18 01:03 junitas