pajowu / signal-backup-decode

Decode Signal Backups
GNU General Public License v3.0
212 stars 17 forks source link

'Failed to prepare statement: CREATE TABLE sqlite_sequence(name,seq): Error { code: Some(1), message: Some("object name reserved for internal use: sqlite_sequence") } #13

Closed strugee closed 5 years ago

strugee commented 5 years ago

Running the program on my backup produces the following error:

$ RUST_BACKTRACE=1 ./signal-backup-decode signal-2019-04-29-04-03-42.backup --password '<omitted>' --sqlite-path out.sqlite3
Database Version: 20d 1 frames, 0 attachments, 54 bytes into file
thread 'main' panicked at 'Failed to prepare statement: CREATE TABLE sqlite_sequence(name,seq): Error { code: Some(1), message: Some("object name reserved for internal use: sqlite_sequence") }', src/libcore/result.rs:997:5
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:70
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:58
             at src/libstd/panicking.rs:200
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:215
   4: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:478
   5: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:385
   6: rust_begin_unwind
             at src/libstd/panicking.rs:312
   7: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
   8: core::result::unwrap_failed
   9: signal_backup_decode::decode_backup
  10: signal_backup_decode::main
  11: std::rt::lang_start::{{closure}}
  12: std::panicking::try::do_call
             at src/libstd/rt.rs:49
             at src/libstd/panicking.rs:297
  13: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:87
  14: std::rt::lang_start_internal
             at src/libstd/panicking.rs:276
             at src/libstd/panic.rs:388
             at src/libstd/rt.rs:48
  15: main
  16: __libc_start_main
  17: _start

This is on Debian 9. Version information:

$ apt policy sqlite3
sqlite3:
  Installed: 3.16.2-5+deb9u1
  Candidate: 3.16.2-5+deb9u1
  Version table:
     3.27.2-2~bpo9+1 100
        100 http://deb.debian.org/debian stretch-backports/main amd64 Packages
 *** 3.16.2-5+deb9u1 500
        500 http://deb.debian.org/debian stretch/main amd64 Packages
        100 /var/lib/dpkg/status

Version information on the host that built the binary (which is different than what I'm running it on, but should have the exact same packages installed because they share the same Qubes OS TemplateVM):

% rustc --version
rustc 1.34.1 (fc50f328b 2019-04-24)

% cargo --version
cargo 1.34.0 (6789d8a0a 2019-04-01)

% apt policy sqlite3
sqlite3:
  Installed: 3.16.2-5+deb9u1
  Candidate: 3.16.2-5+deb9u1
  Version table:
     3.27.2-2~bpo9+1 100
        100 http://deb.debian.org/debian stretch-backports/main amd64 Packages
 *** 3.16.2-5+deb9u1 500
        500 http://deb.debian.org/debian stretch/main amd64 Packages
        100 /var/lib/dpkg/status

The program was installed with cargo install today. Please do let me know what other information I can provide.

strugee commented 5 years ago

I patched the program to dump the SQLite statements it was executing. Here's the end of that:

statement
CREATE TRIGGER sms_au AFTER UPDATE ON sms BEGIN
  INSERT INTO sms_fts(sms_fts, rowid, body, thread_id) VALUES('delete', old._id, old.body, old.thread_id);
  INSERT INTO sms_fts(rowid, body, thread_id) VALUES(new._id, new.body, new.thread_id);
END

statement
CREATE VIRTUAL TABLE mms_fts USING fts5(body, thread_id UNINDEXED, content=mms, content_rowid=_id)

statement
CREATE TRIGGER mms_ai AFTER INSERT ON mms BEGIN
  INSERT INTO mms_fts(rowid, body, thread_id) VALUES (new._id, new.body, new.thread_id);
END

statement
CREATE TRIGGER mms_ad AFTER DELETE ON mms BEGIN
  INSERT INTO mms_fts(mms_fts, rowid, body, thread_id) VALUES('delete', old._id, old.body, old.thread_id);
END

statement
CREATE TRIGGER mms_au AFTER UPDATE ON mms BEGIN
  INSERT INTO mms_fts(mms_fts, rowid, body, thread_id) VALUES('delete', old._id, old.body, old.thread_id);
  INSERT INTO mms_fts(rowid, body, thread_id) VALUES(new._id, new.body, new.thread_id);
END

statement
CREATE TABLE job_spec(_id INTEGER PRIMARY KEY AUTOINCREMENT, job_spec_id TEXT UNIQUE, factory_key TEXT, queue_key TEXT, create_time INTEGER, next_run_attempt_time INTEGER, run_attempt INTEGER, max_attempts INTEGER, max_backoff INTEGER, max_instances INTEGER, lifespan INTEGER, serialized_data TEXT, is_running INTEGER)

statementlly exported 35 frames, 0 attachments, 8341 bytes into file
CREATE TABLE sqlite_sequence(name,seq)

thread 'main' panicked at 'Failed to prepare statement: CREATE TABLE sqlite_sequence(name,seq): Error { code: Some(1), message: Some("object name reserved for internal use: sqlite_sequence") }', src/libcore/result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
pajowu commented 5 years ago

Okay, this seems to be a bug in signal itself, I will apply the same patch as the signal app (https://github.com/signalapp/Signal-Android/commit/128da6db04d204dee437012d41dec06be4717537)

pajowu commented 5 years ago

Could you please try again with d938f75 applied?

strugee commented 5 years ago

I checked out that patch and rebuilt, then reran the program. It's still running, but it hasn't crashed yet so I think it's fine.

strugee commented 5 years ago

Closing since d938f75 is already in master.