1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 20:22:55 +08:00

Guard against null values getting inserted into database during score/beatmap imports

This commit is contained in:
Dean Herbert 2022-01-17 14:02:15 +09:00
parent 744084b418
commit a0e2106468
2 changed files with 6 additions and 1 deletions

View File

@ -63,6 +63,11 @@ namespace osu.Game.Scoring
if (!model.Ruleset.IsManaged)
model.Ruleset = realm.Find<RulesetInfo>(model.Ruleset.ShortName);
// These properties are known to be non-null, but these final checks ensure a null hasn't come from somewhere (or the refetch has failed).
// Under no circumstance do we want these to be written to realm as null.
if (model.BeatmapInfo == null) throw new ArgumentNullException(nameof(model.BeatmapInfo));
if (model.Ruleset == null) throw new ArgumentNullException(nameof(model.Ruleset));
if (string.IsNullOrEmpty(model.StatisticsJson))
model.StatisticsJson = JsonConvert.SerializeObject(model.Statistics);
}

View File

@ -64,7 +64,7 @@ namespace osu.Game.Stores
// ensure we aren't trying to add a new ruleset to the database
// this can happen in tests, mostly
if (!b.Ruleset.IsManaged)
b.Ruleset = realm.Find<RulesetInfo>(b.Ruleset.ShortName);
b.Ruleset = realm.Find<RulesetInfo>(b.Ruleset.ShortName) ?? throw new ArgumentNullException(nameof(b.Ruleset));
}
validateOnlineIds(beatmapSet, realm);