Skip to content

Commit

Permalink
Fix int overflow when using fillr in negative y-coordinates (#2082)
Browse files Browse the repository at this point in the history
  • Loading branch information
dordsor21 authored Sep 19, 2023
1 parent 9456535 commit 3627002
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)));

Expand Down

0 comments on commit 3627002

Please sign in to comment.