Skip to content

Commit

Permalink
Fix int overflow when using fill and fillr in negative y-coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
dordsor21 committed May 4, 2022
1 parent c1b5f8c commit 70fa59c
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 70fa59c

Please sign in to comment.