Add restrictions to region copy

This commit is contained in:
Jesse Boyd 2017-02-02 10:29:37 +11:00
parent a9cafb13a2
commit 6439f28c0c
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 14 additions and 3 deletions

View File

@ -128,7 +128,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
MainUtil.handleError(e);
}
this.raf = new BufferedRandomAccessFile(file, "rw", 16);
long volume = width * height * length * 2l + HEADER_SIZE;
long volume = (long) width * (long) height * (long) length * 2l + (long) HEADER_SIZE;
raf.setLength(0);
raf.setLength(volume);
// write length etc

View File

@ -26,6 +26,7 @@ import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.RunnableVal2;
import com.boydti.fawe.object.clipboard.ReadOnlyClipboard;
import com.boydti.fawe.object.clipboard.WorldCutClipboard;
import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.object.io.FastByteArrayOutputStream;
import com.boydti.fawe.util.ImgurUtility;
import com.boydti.fawe.util.MaskTraverser;
@ -139,6 +140,12 @@ public class ClipboardCommands {
public void copy(Player player, LocalSession session, EditSession editSession,
@Selection Region region, @Switch('e') boolean copyEntities,
@Switch('m') Mask mask) throws WorldEditException {
Vector min = region.getMinimumPoint();
Vector max = region.getMaximumPoint();
long volume = (((long)max.getX() - (long)min.getX() + 1) * ((long)max.getY() - (long)min.getY() + 1) * ((long)max.getZ() - (long)min.getZ() + 1));
if (volume >= Integer.MAX_VALUE) {
throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS);
}
BlockArrayClipboard clipboard = new BlockArrayClipboard(region, player.getUniqueId());
@ -175,7 +182,6 @@ public class ClipboardCommands {
public void lazyCut(Player player, LocalSession session, EditSession editSession,
@Selection final Region region, @Switch('e') boolean copyEntities,
@Switch('m') Mask mask) throws WorldEditException {
final Vector origin = region.getMinimumPoint();
final int mx = origin.getBlockX();
final int my = origin.getBlockY();
@ -205,7 +211,12 @@ public class ClipboardCommands {
public void cut(Player player, LocalSession session, EditSession editSession,
@Selection Region region, @Optional("air") Pattern leavePattern, @Switch('e') boolean copyEntities,
@Switch('m') Mask mask) throws WorldEditException {
Vector min = region.getMinimumPoint();
Vector max = region.getMaximumPoint();
long volume = (((long)max.getX() - (long)min.getX() + 1) * ((long)max.getY() - (long)min.getY() + 1) * ((long)max.getZ() - (long)min.getZ() + 1));
if (volume >= Integer.MAX_VALUE) {
throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS);
}
BlockArrayClipboard clipboard = new BlockArrayClipboard(region, player.getUniqueId());
clipboard.setOrigin(session.getPlacementPosition(player));
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());