1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 03:42:57 +08:00

Fix beatmap potentially loading in a bad state

Over-caching could mean that a beatmap could load and cause a late
crash. Let's catch it early to avoid such a crash occurring.
This commit is contained in:
Dean Herbert 2024-02-17 19:00:43 +08:00
parent 415a65bf59
commit 7f82f10317
No known key found for this signature in database

View File

@ -9,6 +9,7 @@ using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Extensions;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Rendering.Dummy;
using osu.Framework.Graphics.Textures;
@ -143,8 +144,6 @@ namespace osu.Game.Beatmaps
{
string fileStorePath = BeatmapSetInfo.GetPathForFile(BeatmapInfo.Path);
// TODO: check validity of file
var stream = GetStream(fileStorePath);
if (stream == null)
@ -153,6 +152,12 @@ namespace osu.Game.Beatmaps
return null;
}
if (stream.ComputeMD5Hash() != BeatmapInfo.MD5Hash)
{
Logger.Log($"Beatmap failed to load (file {BeatmapInfo.Path} does not have the expected hash).", level: LogLevel.Error);
return null;
}
using (var reader = new LineBufferedReader(stream))
return Decoder.GetDecoder<Beatmap>(reader).Decode(reader);
}