Skip to content

Commit

Permalink
Add overflow protection to editsession method
Browse files Browse the repository at this point in the history
  • Loading branch information
dordsor21 committed Apr 20, 2022
1 parent f805017 commit 807227f
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 807227f

Please sign in to comment.