From 65667ccd074cec3a600a6d5f117beac04ebac05f Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Tue, 8 Aug 2023 17:30:30 -0700 Subject: [PATCH] Fix race condition on UpgradeData.BlockFixers class init The CHUNKY_FIXERS field is modified during the constructors of the BlockFixers, but the code that uses CHUNKY_FIXERS does not properly ensure that BlockFixers has been initialised before using it, leading to a possible race condition where instances of BlockFixers are accessed before they have initialised correctly. We can force the class to initialise fully before accessing the field by calling any method on the class, and for convenience we use values(). Fixes https://github.com/PaperMC/Folia/issues/141 --- ...on-on-UpgradeData.BlockFixers-class-.patch | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 patches/server/0025-Fix-race-condition-on-UpgradeData.BlockFixers-class-.patch diff --git a/patches/server/0025-Fix-race-condition-on-UpgradeData.BlockFixers-class-.patch b/patches/server/0025-Fix-race-condition-on-UpgradeData.BlockFixers-class-.patch new file mode 100644 index 0000000..7e19a4b --- /dev/null +++ b/patches/server/0025-Fix-race-condition-on-UpgradeData.BlockFixers-class-.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Spottedleaf +Date: Tue, 8 Aug 2023 17:29:33 -0700 +Subject: [PATCH] Fix race condition on UpgradeData.BlockFixers class init + +The CHUNKY_FIXERS field is modified during the constructors +of the BlockFixers, but the code that uses CHUNKY_FIXERS does +not properly ensure that BlockFixers has been initialised before +using it, leading to a possible race condition where instances of +BlockFixers are accessed before they have initialised correctly. + +We can force the class to initialise fully before accessing the +field by calling any method on the class, and for convenience +we use values(). + +diff --git a/src/main/java/net/minecraft/world/level/chunk/UpgradeData.java b/src/main/java/net/minecraft/world/level/chunk/UpgradeData.java +index 8e2a7ea230fedb9094a159a83c9d69f6df3832f3..55993be2a46f6fd8635d0562aa2b76530bd9ad3d 100644 +--- a/src/main/java/net/minecraft/world/level/chunk/UpgradeData.java ++++ b/src/main/java/net/minecraft/world/level/chunk/UpgradeData.java +@@ -116,6 +116,7 @@ public class UpgradeData { + Fluid fluid = tick.type() == Fluids.EMPTY ? level.getFluidState(tick.pos()).getType() : tick.type(); + level.scheduleTick(tick.pos(), fluid, tick.delay(), tick.priority()); + }); ++ UpgradeData.BlockFixers.values(); // Folia - force the class init so that we don't access CHUNKY_FIXERS before all BlockFixers are initialised + CHUNKY_FIXERS.forEach((logic) -> { + logic.processChunk(level); + });