1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 17:43:05 +08:00

Merge pull request #26468 from frenzibyte/fix-skin-parsing

Fix mania skin array decoder not handling malformed entries rigorously
This commit is contained in:
Bartłomiej Dach 2024-01-12 12:52:02 +01:00 committed by GitHub
commit 593ca9f84f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 1 deletions

View File

@ -0,0 +1,3 @@
[Mania]
Keys: 4
ColumnLineWidth: 3,,3,3,3

View File

@ -114,5 +114,25 @@ namespace osu.Game.Tests.Skins
Assert.That(configs[0].MinimumColumnWidth, Is.EqualTo(16));
}
}
[Test]
public void TestParseArrayWithSomeEmptyElements()
{
var decoder = new LegacyManiaSkinDecoder();
using (var resStream = TestResources.OpenResource("mania-skin-broken-array.ini"))
using (var stream = new LineBufferedReader(resStream))
{
var configs = decoder.Decode(stream);
Assert.That(configs.Count, Is.EqualTo(1));
Assert.That(configs[0].ColumnLineWidth.Length, Is.EqualTo(5));
Assert.That(configs[0].ColumnLineWidth[0], Is.EqualTo(3));
Assert.That(configs[0].ColumnLineWidth[1], Is.EqualTo(0)); // malformed entry, should be parsed as zero
Assert.That(configs[0].ColumnLineWidth[2], Is.EqualTo(3));
Assert.That(configs[0].ColumnLineWidth[3], Is.EqualTo(3));
Assert.That(configs[0].ColumnLineWidth[4], Is.EqualTo(3));
}
}
}
}

View File

@ -155,7 +155,15 @@ namespace osu.Game.Skinning
if (i >= output.Length)
break;
output[i] = float.Parse(values[i], CultureInfo.InvariantCulture) * (applyScaleFactor ? LegacyManiaSkinConfiguration.POSITION_SCALE_FACTOR : 1);
if (!float.TryParse(values[i], NumberStyles.Float, CultureInfo.InvariantCulture, out float parsedValue))
// some skins may provide incorrect entries in array values. to match stable behaviour, read such entries as zero.
// see: https://github.com/ppy/osu/issues/26464, stable code: https://github.com/peppy/osu-stable-reference/blob/3ea48705eb67172c430371dcfc8a16a002ed0d3d/osu!/Graphics/Skinning/Components/Section.cs#L134-L137
parsedValue = 0;
if (applyScaleFactor)
parsedValue *= LegacyManiaSkinConfiguration.POSITION_SCALE_FACTOR;
output[i] = parsedValue;
}
}
}