Skip to content

Commit 0c9fe12

Browse files
committed
Fix incorrect validation of circle size / key count
The big issue is that the range specified on the attribute was [1, 18] which only makes sense in mania. The small issue that while the range was checked, nothing decimal should really be allowed for mania anyway. A significant amount of this is kind of much-of-muchness because `LegacyBeatmapDecoder` already does clamping on this: https://github.com/ppy/osu/blob/834d63d1deacf0be0c4e76cd5d47cee136fbb49a/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs#L113-L131 so the checks are kind of dead in practice, but I'd rather have them not, what with users' propensity to try and break stuff and not have us notice that it happened. The game package bump here is significant because it exposes `LegacyBeatmapDecoder.MAX_MANIA_KEY_COUNT`.
1 parent e4bc35a commit 0c9fe12

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

osu.Server.BeatmapSubmission.Tests/BeatmapSubmissionControllerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ osu file format v14
16361636
{
16371637
Assert.False(response.IsSuccessStatusCode);
16381638

1639-
Assert.Contains(playmode == 3 ? "The circle size of the beatmap is out of range." : "The key count of the beatmap is invalid.",
1639+
Assert.Contains(playmode == 3 ? "The key count of the beatmap is invalid." : "The circle size of the beatmap is out of range.",
16401640
(await response.Content.ReadFromJsonAsync<ErrorResponse>())!.Error);
16411641
}
16421642
}

osu.Server.BeatmapSubmission/Models/Database/osu_beatmap.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
using System.ComponentModel.DataAnnotations;
77
using osu.Game.Beatmaps;
8+
using osu.Game.Beatmaps.Formats;
89
using osu.Server.BeatmapSubmission.Models.Database.Validation;
910

1011
namespace osu.Server.BeatmapSubmission.Models.Database
1112
{
12-
public class osu_beatmap
13+
public class osu_beatmap : IValidatableObject
1314
{
1415
public uint beatmap_id { get; set; }
1516
public uint? beatmapset_id { get; set; }
@@ -45,7 +46,6 @@ public class osu_beatmap
4546
[Range(0.0, 10.0, ErrorMessage = "The drain rate of the beatmap is out of range.")]
4647
public float diff_drain { get; set; }
4748

48-
[Range(1.0, 18.0, ErrorMessage = "The circle size / key count of the beatmap is out of range.")]
4949
public float diff_size { get; set; }
5050

5151
[Range(0.0, 10.0, ErrorMessage = "The overall difficulty of the beatmap is out of range.")]
@@ -69,5 +69,29 @@ public class osu_beatmap
6969
// deleted_at skipped on purpose
7070

7171
public float bpm { get; set; }
72+
73+
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
74+
{
75+
switch (playmode)
76+
{
77+
case 0:
78+
case 1:
79+
case 2:
80+
{
81+
if (diff_size < 0 || diff_size > 10)
82+
yield return new ValidationResult("The circle size of the beatmap is out of range.");
83+
84+
break;
85+
}
86+
87+
case 3:
88+
{
89+
if (diff_size != (int)diff_size || diff_size < 1 || diff_size > LegacyBeatmapDecoder.MAX_MANIA_KEY_COUNT)
90+
yield return new ValidationResult("The key count of the beatmap is invalid.");
91+
92+
break;
93+
}
94+
}
95+
}
7296
}
7397
}

osu.Server.BeatmapSubmission/osu.Server.BeatmapSubmission.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
<PackageReference Include="DogStatsD-CSharp-Client" Version="8.0.0" />
2020
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.10" />
2121
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.10"/>
22-
<PackageReference Include="ppy.osu.Game" Version="2025.304.0" />
23-
<PackageReference Include="ppy.osu.Game.Rulesets.Catch" Version="2025.304.0" />
24-
<PackageReference Include="ppy.osu.Game.Rulesets.Mania" Version="2025.304.0" />
25-
<PackageReference Include="ppy.osu.Game.Rulesets.Osu" Version="2025.304.0" />
26-
<PackageReference Include="ppy.osu.Game.Rulesets.Taiko" Version="2025.304.0" />
22+
<PackageReference Include="ppy.osu.Game" Version="2025.420.0" />
23+
<PackageReference Include="ppy.osu.Game.Rulesets.Catch" Version="2025.420.0" />
24+
<PackageReference Include="ppy.osu.Game.Rulesets.Mania" Version="2025.420.0" />
25+
<PackageReference Include="ppy.osu.Game.Rulesets.Osu" Version="2025.420.0" />
26+
<PackageReference Include="ppy.osu.Game.Rulesets.Taiko" Version="2025.420.0" />
2727
<PackageReference Include="ppy.osu.Server.OsuQueueProcessor" Version="2024.1111.0" />
2828
<PackageReference Include="Sentry.AspNetCore" Version="5.2.0" />
2929
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.3.1" />

0 commit comments

Comments
 (0)