From ac863259496e21af947e6c753cc805d71fee248d Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Wed, 4 May 2022 14:58:52 +0100 Subject: [PATCH] Fix int overflow when using fill and fillr in negative y-coordinates --- .../src/main/java/com/sk89q/worldedit/EditSession.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index 5bd31cb839..1d161cb3b3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -1458,10 +1458,17 @@ public int fillXZ(BlockVector3 origin, Pattern pattern, double radius, int depth checkArgument(radius >= 0, "radius >= 0"); checkArgument(depth >= 1, "depth >= 1"); + // Avoid int overflow (negative coordinate space allows for overflow back round to positive if the depth is large enough). + // Depth is always 1 or greater, thus the lower bound should always be <= origin y. + int lowerBound = origin.getBlockY() - depth + 1; + if (lowerBound > origin.getBlockY()) { + lowerBound = Integer.MIN_VALUE; + } + Mask mask = new MaskIntersection( new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), new BoundedHeightMask( - Math.max(origin.getBlockY() - depth + 1, minY), + Math.max(lowerBound, minY), Math.min(maxY, origin.getBlockY()) ), Masks.negate(new ExistingBlockMask(this))