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 a6397ffb49..3d2441a5d7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -1002,10 +1002,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; + } + MaskIntersection mask = new MaskIntersection( new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), new BoundedHeightMask( - Math.max(origin.getBlockY() - depth + 1, getWorld().getMinY()), + Math.max(lowerBound, getWorld().getMinY()), Math.min(getWorld().getMaxY(), origin.getBlockY())), Masks.negate(new ExistingBlockMask(this)));