mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
RestoreManager: Validate all elements in session file
Session file can be corrupted or have data from unsupported version inside the file.
This commit is contained in:
parent
e6b220a87a
commit
6985a8567a
|
@ -122,6 +122,11 @@ BrowserWindow::SavedWindow::SavedWindow(BrowserWindow *window)
|
|||
|
||||
bool BrowserWindow::SavedWindow::isValid() const
|
||||
{
|
||||
for (const WebTab::SavedTab &tab : qAsConst(tabs)) {
|
||||
if (!tab.isValid()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return currentTab > -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,12 +26,19 @@ static const int restoreDataVersion = 2;
|
|||
|
||||
bool RestoreData::isValid() const
|
||||
{
|
||||
for (const BrowserWindow::SavedWindow &window : qAsConst(windows)) {
|
||||
if (!window.isValid()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return !windows.isEmpty();
|
||||
}
|
||||
|
||||
void RestoreData::clear()
|
||||
{
|
||||
windows.clear();
|
||||
crashedSession.clear();
|
||||
closedWindows.clear();
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &stream, const RestoreData &data)
|
||||
|
@ -155,27 +162,9 @@ static void loadVersion3(QDataStream &stream, RestoreData &data)
|
|||
// static
|
||||
bool RestoreManager::validateFile(const QString &file)
|
||||
{
|
||||
if (!QFile::exists(file)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QFile recoveryFile(file);
|
||||
if (!recoveryFile.open(QIODevice::ReadOnly)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QDataStream stream(&recoveryFile);
|
||||
|
||||
int version;
|
||||
stream >> version;
|
||||
|
||||
if (version == Qz::sessionVersion || version == 0x0003 || version == (0x0003 | 0x050000)) {
|
||||
int windowCount;
|
||||
stream >> windowCount;
|
||||
return windowCount > 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
RestoreData data;
|
||||
createFromFile(file, data);
|
||||
return data.isValid();
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
Loading…
Reference in New Issue
Block a user