History

Add guard to JSON.parse in readMigrationJournal

Griffin committed 4 months ago

Commit 1663b1a1 parent 50217431 file · +7 −3Browse files

Unified · Split

apps/local/src/db/v1-v2-migration.ts+7−3
@@ -1124,9 +1124,13 @@ const removeMigrationJournal = (path: string): void => { · 1123 unmodified lines
1124 1124
1125const readMigrationJournal = (path: string): MigrationJournal | null => {1125const readMigrationJournal = (path: string): MigrationJournal | null => {
1126 if (!fs.existsSync(path)) return null;1126 if (!fs.existsSync(path)) return null;
1127 const parsed = JSON.parse(fs.readFileSync(path, "utf-8")) as MigrationJournal;1127 try {
1128 if (parsed.version !== 1) return null;1128 const parsed = JSON.parse(fs.readFileSync(path, "utf-8")) as MigrationJournal;
1129 return parsed;1129 if (parsed.version !== 1) return null;
1130 return parsed;
1131 } catch {
1132 return null;
1133 }
1130};1134};
1131 1135
1132const authBackupInfoForMigration = (1136const authBackupInfoForMigration = (