1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 05:22:54 +08:00

Add protection against arbitrary exceptions from GetModsFor()

This commit is contained in:
Bartłomiej Dach 2022-06-15 17:22:39 +02:00
parent 665ef5fdcc
commit e74b563b91
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497

View File

@ -511,23 +511,34 @@ namespace osu.Game
if (instance == null)
{
// reject the change if the ruleset is not available.
Ruleset.Value = r.OldValue?.Available == true ? r.OldValue : RulesetStore.AvailableRulesets.First();
revertRulesetChange();
return;
}
var dict = new Dictionary<ModType, IReadOnlyList<Mod>>();
foreach (ModType type in Enum.GetValues(typeof(ModType)))
try
{
dict[type] = instance.GetModsFor(type)
.Where(mod => mod != null)
.ToList();
foreach (ModType type in Enum.GetValues(typeof(ModType)))
{
dict[type] = instance.GetModsFor(type)
.Where(mod => mod != null)
.ToList();
}
}
catch (Exception e)
{
Logger.Error(e, $"Could not load mods for \"{instance.RulesetInfo.Name}\" ruleset. Current ruleset has been rolled back.");
revertRulesetChange();
return;
}
if (!SelectedMods.Disabled)
SelectedMods.Value = Array.Empty<Mod>();
AvailableMods.Value = dict;
void revertRulesetChange() => Ruleset.Value = r.OldValue?.Available == true ? r.OldValue : RulesetStore.AvailableRulesets.First();
}
private int allowableExceptions;