Skip to content

Commit edb37d0

Browse files
authored
Merge pull request #52 from bdach/disallow-old-osu-versions
Disallow uploads of beatmaps with file version below v14
2 parents bda4b1a + 99ccae3 commit edb37d0

File tree

8 files changed

+34
-4
lines changed

8 files changed

+34
-4
lines changed

osu.Server.BeatmapSubmission.Tests/BeatmapSubmissionControllerTest.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,31 @@ public async Task TestUploadFullPackage_FailsIfMetadataTooLong()
11631163
Assert.Contains("Beatmap difficulty names must not exceed 80 characters.", (await response.Content.ReadFromJsonAsync<ErrorResponse>())!.Error);
11641164
}
11651165

1166+
[Fact]
1167+
public async Task TestUploadFullPackage_FailsIfOsuFileFormatVersionTooOld()
1168+
{
1169+
using var db = await DatabaseAccess.GetConnectionAsync();
1170+
await db.ExecuteAsync("INSERT INTO `phpbb_users` (`user_id`, `username`, `username_clean`, `country_acronym`, `user_permissions`, `user_sig`, `user_occ`, `user_interests`) VALUES (1000, 'test', 'test', 'JP', '', '', '', '')");
1171+
1172+
await db.ExecuteAsync(@"INSERT INTO `osu_beatmapsets` (`beatmapset_id`, `user_id`, `creator`, `approved`, `thread_id`, `active`, `submit_date`) VALUES (241526, 1000, 'test user', -1, 0, -1, CURRENT_TIMESTAMP)");
1173+
1174+
foreach (uint beatmapId in new uint[] { 557810 })
1175+
await db.ExecuteAsync(@"INSERT INTO `osu_beatmaps` (`beatmap_id`, `user_id`, `beatmapset_id`, `approved`) VALUES (@beatmapId, 1000, 241526, -1)", new { beatmapId = beatmapId });
1176+
1177+
var request = new HttpRequestMessage(HttpMethod.Put, "/beatmapsets/241526");
1178+
1179+
using var content = new MultipartFormDataContent($"{Guid.NewGuid()}----");
1180+
using var stream = TestResources.GetResource("old-osu-version.osz")!;
1181+
content.Add(new StreamContent(stream), "beatmapArchive", osz_filename);
1182+
request.Content = content;
1183+
request.Headers.Add(HeaderBasedAuthenticationHandler.USER_ID_HEADER, "1000");
1184+
1185+
var response = await Client.SendAsync(request);
1186+
Assert.False(response.IsSuccessStatusCode);
1187+
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
1188+
Assert.Contains("Version of file \"Soleily - Renatus (test) [old version].osu\" is too old (should be v14 or higher)", (await response.Content.ReadFromJsonAsync<ErrorResponse>())!.Error);
1189+
}
1190+
11661191
[Fact]
11671192
public async Task TestPatchPackage()
11681193
{
Binary file not shown.

osu.Server.BeatmapSubmission.Tests/Resources/Soleily - Renatus (test) [Platter 2].osu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
osu file format v13
1+
osu file format v14
22

33
[General]
44
AudioFilename: 03. Renatus - Soleily 192kbps.mp3
575 Bytes
Binary file not shown.
329 Bytes
Binary file not shown.
Binary file not shown.
1.49 KB
Binary file not shown.

osu.Server.BeatmapSubmission/Services/BeatmapPackageParser.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,15 @@ public BeatmapPackageParseResult Parse(uint beatmapSetId, ArchiveReader archiveR
8888

8989
private static BeatmapContent getBeatmapContent(string filePath, Stream contents)
9090
{
91-
var decoder = new LegacyBeatmapDecoder();
92-
var beatmap = decoder.Decode(new LineBufferedReader(contents));
91+
string fileName = Path.GetFileName(filePath);
92+
using var reader = new LineBufferedReader(contents, leaveOpen: true);
93+
var decoder = Decoder.GetDecoder<Beatmap>(reader);
94+
var beatmap = decoder.Decode(reader);
9395

94-
return new BeatmapContent(Path.GetFileName(filePath), contents.ComputeMD5Hash(), beatmap);
96+
if (beatmap.BeatmapVersion < LegacyBeatmapDecoder.LATEST_VERSION)
97+
throw new InvariantException($"Version of file \"{fileName}\" is too old (should be v14 or higher)");
98+
99+
return new BeatmapContent(fileName, contents.ComputeMD5Hash(), beatmap);
95100
}
96101

97102
private osu_beatmapset constructDatabaseRowForBeatmapset(uint beatmapSetId, ArchiveReader archiveReader, ICollection<BeatmapContent> beatmaps)

0 commit comments

Comments
 (0)