Skip to content

Commit 449b6d3

Browse files
committed
Fix text flow arbitrary drawable wrapper accessing child in an unsafe manner
Closes #34126. I'm not really sure how that issue could have ever happened to begin with but I can see a way to make it hopefully safer. If it fails again then it's clearly goblins.
1 parent b4502d3 commit 449b6d3

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

osu.Game/Graphics/Containers/OsuTextFlowContainer.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
33

4-
#nullable disable
5-
64
using System;
75
using osu.Framework.Extensions.IEnumerableExtensions;
86
using osu.Framework.Graphics;
@@ -14,23 +12,27 @@ namespace osu.Game.Graphics.Containers
1412
{
1513
public partial class OsuTextFlowContainer : TextFlowContainer
1614
{
17-
public OsuTextFlowContainer(Action<SpriteText> defaultCreationParameters = null)
15+
public OsuTextFlowContainer(Action<SpriteText>? defaultCreationParameters = null)
1816
: base(defaultCreationParameters)
1917
{
2018
}
2119

2220
protected override SpriteText CreateSpriteText() => new OsuSpriteText();
2321

24-
public ITextPart AddArbitraryDrawable(Drawable drawable) => AddPart(new TextPartManual(new ArbitraryDrawableWrapper { Child = drawable }.Yield()));
22+
public ITextPart AddArbitraryDrawable(Drawable drawable) => AddPart(new TextPartManual(new ArbitraryDrawableWrapper(drawable).Yield()));
2523

26-
public ITextPart AddIcon(IconUsage icon, Action<SpriteText> creationParameters = null) => AddText(icon.Icon.ToString(), creationParameters);
24+
public ITextPart AddIcon(IconUsage icon, Action<SpriteText>? creationParameters = null) => AddText(icon.Icon.ToString(), creationParameters);
2725

2826
private partial class ArbitraryDrawableWrapper : Container, IHasLineBaseHeight
2927
{
30-
public float LineBaseHeight => (Child as IHasLineBaseHeight)?.LineBaseHeight ?? DrawHeight;
28+
private readonly IHasLineBaseHeight? lineBaseHeightSource;
29+
30+
public float LineBaseHeight => lineBaseHeightSource?.LineBaseHeight ?? DrawHeight;
3131

32-
public ArbitraryDrawableWrapper()
32+
public ArbitraryDrawableWrapper(Drawable drawable)
3333
{
34+
Child = drawable;
35+
lineBaseHeightSource = drawable as IHasLineBaseHeight;
3436
AutoSizeAxes = Axes.Both;
3537
}
3638
}

osu.Game/Screens/Menu/SupporterDisplay.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ protected override void LoadComplete()
105105

106106
Schedule(() =>
107107
{
108-
heart?.FlashColour(Color4.White, 750, Easing.OutQuint).Loop();
108+
heart.FlashColour(Color4.White, 750, Easing.OutQuint).Loop();
109109
});
110110
});
111111
}, true);

0 commit comments

Comments
 (0)