Skip to content

Commit

Permalink
Merge pull request #1742 from ghutchis/prevent-download-crash
Browse files Browse the repository at this point in the history
Prevent a possible unhandled exception from parsing JSON
  • Loading branch information
ghutchis authored Oct 17, 2024
2 parents b027e40 + 50505c9 commit f0d427e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions avogadro/qtplugins/plugindownloader/downloaderwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ void DownloaderWidget::updateRepoData()
// Reading the data from the response
QByteArray bytes = m_reply->readAll();

// quick checks that it's a valid JSON reply
// it should be a list, so [ ] characters
if (bytes.isEmpty() || bytes[0] != '[' || bytes[bytes.size() - 1] != ']') {
QMessageBox::warning(this, tr("Error"),
tr("Error downloading plugin data."));
return;
}
// does it parse as JSON cleanly?
if (!json::accept(bytes.data())) {
QMessageBox::warning(this, tr("Error"), tr("Error parsing plugin data."));
return;
}

// parse the json
m_root = json::parse(bytes.data());
int numRepos = m_root.size();
Expand Down

0 comments on commit f0d427e

Please sign in to comment.