Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix classic scoring overflowing in osu! ruleset due to integer multiplication overflow #25546

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions osu.Game.Tests/Rulesets/Scoring/ScoreProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Catch;
using osu.Game.Rulesets.Difficulty;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Judgements;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Taiko;
using osu.Game.Rulesets.UI;
using osu.Game.Scoring.Legacy;
using osu.Game.Tests.Beatmaps;
Expand Down Expand Up @@ -117,6 +120,35 @@ public void TestFourVariousResultsOneMiss(ScoringMode scoringMode, HitResult hit
Assert.That(scoreProcessor.GetDisplayScore(scoringMode), Is.EqualTo(expectedScore).Within(0.5d));
}

[TestCase(typeof(OsuRuleset))]
[TestCase(typeof(TaikoRuleset))]
[TestCase(typeof(CatchRuleset))]
[TestCase(typeof(ManiaRuleset))]
public void TestBeatmapWithALotOfObjectsDoesNotOverflowClassicScore(Type rulesetType)
{
const int object_count = 999999;

var ruleset = (Ruleset)Activator.CreateInstance(rulesetType)!;
scoreProcessor = new ScoreProcessor(ruleset);

var largeBeatmap = new TestBeatmap(ruleset.RulesetInfo)
{
HitObjects = new List<HitObject>(Enumerable.Repeat(new TestHitObject(HitResult.Great), object_count))
};
scoreProcessor.ApplyBeatmap(largeBeatmap);

for (int i = 0; i < object_count; ++i)
{
var judgementResult = new JudgementResult(largeBeatmap.HitObjects[i], largeBeatmap.HitObjects[i].CreateJudgement())
{
Type = HitResult.Great
};
scoreProcessor.ApplyResult(judgementResult);
}

Assert.That(scoreProcessor.GetDisplayScore(ScoringMode.Classic), Is.GreaterThan(0));
}

[Test]
public void TestEmptyBeatmap(
[Values(ScoringMode.Standardised, ScoringMode.Classic)]
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Scoring/Legacy/ScoreInfoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static long convertStandardisedToClassic(int rulesetId, long standardise
switch (rulesetId)
{
case 0:
return (long)Math.Round((objectCount * objectCount * 32.57 + 100000) * standardisedTotalScore / ScoreProcessor.MAX_SCORE);
return (long)Math.Round((Math.Pow(objectCount, 2) * 32.57 + 100000) * standardisedTotalScore / ScoreProcessor.MAX_SCORE);

case 1:
return (long)Math.Round((objectCount * 1109 + 100000) * standardisedTotalScore / ScoreProcessor.MAX_SCORE);
Expand Down