Avoid int overflow when using fillr in negative coords (#1711)

Fix int overflow when using fill and fillr in negative y-coordinates
Dieser Commit ist enthalten in:
Jordan 2022-06-05 19:52:36 +01:00 committet von GitHub
Ursprung 198c6b7800
Commit 32231b48fe
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23

Datei anzeigen

@ -1459,10 +1459,17 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
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))