From 90130e3be0c0d3bd2fff1afd1625d6cf4c565ba9 Mon Sep 17 00:00:00 2001 From: Ken Powers Date: Tue, 31 Mar 2020 12:22:14 -0400 Subject: [PATCH] Don't start Signal if DB version is greater than we expect --- app/sql.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/sql.js b/app/sql.js index 799c28f571..d0f47aec91 100644 --- a/app/sql.js +++ b/app/sql.js @@ -1464,18 +1464,25 @@ async function updateSchema(instance) { const sqliteVersion = await getSQLiteVersion(instance); const sqlcipherVersion = await getSQLCipherVersion(instance); const userVersion = await getUserVersion(instance); + const maxUserVersion = SCHEMA_VERSIONS.length; const schemaVersion = await getSchemaVersion(instance); console.log( 'updateSchema:\n', ` Current user_version: ${userVersion};\n`, - ` Most recent db schema: ${SCHEMA_VERSIONS.length};\n`, + ` Most recent db schema: ${maxUserVersion};\n`, ` SQLite version: ${sqliteVersion};\n`, ` SQLCipher version: ${sqlcipherVersion};\n`, ` (deprecated) schema_version: ${schemaVersion};\n` ); - for (let index = 0, max = SCHEMA_VERSIONS.length; index < max; index += 1) { + if (userVersion > maxUserVersion) { + throw new Error( + `SQL: User version is ${userVersion} but the expected maximum version is ${maxUserVersion}. Did you try to start an old version of Signal?` + ); + } + + for (let index = 0; index < maxUserVersion; index += 1) { const runSchemaUpdate = SCHEMA_VERSIONS[index]; // Yes, we really want to do this asynchronously, in order