From a080735b836a29658e4170891e6c4e5fa03b074f Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 20 Feb 2017 07:46:30 +1100 Subject: [PATCH] Fix stack outside region --- build.gradle | 2 +- .../fawe/object/extent/FastWorldEditExtent.java | 5 +++++ .../com/boydti/fawe/object/extent/NullExtent.java | 5 +++++ .../main/java/com/boydti/fawe/util/WEManager.java | 5 ++++- .../main/java/com/sk89q/worldedit/EditSession.java | 12 ++++++++++-- .../worldedit/extent/AbstractDelegateExtent.java | 5 +++++ .../function/operation/ForwardExtentCopy.java | 3 ++- .../worldedit/function/visitor/RegionVisitor.java | 5 +++++ 8 files changed, 37 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 66cf72d1..4085ad48 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ ext { date = git.head().date.format("yy.MM.dd") revision = "-${git.head().abbreviatedId}" parents = git.head().parentIds; - index = -72; // Offset to mach CI + index = -73; // Offset to mach CI int major, minor, patch; major = minor = patch = 0; for (;parents != null && !parents.isEmpty();index++) { diff --git a/core/src/main/java/com/boydti/fawe/object/extent/FastWorldEditExtent.java b/core/src/main/java/com/boydti/fawe/object/extent/FastWorldEditExtent.java index 55ef380f..2cd5ea2e 100644 --- a/core/src/main/java/com/boydti/fawe/object/extent/FastWorldEditExtent.java +++ b/core/src/main/java/com/boydti/fawe/object/extent/FastWorldEditExtent.java @@ -82,6 +82,11 @@ public class FastWorldEditExtent extends AbstractDelegateExtent implements HasFa return null; } + @Override + public String toString() { + return super.toString() + ":" + queue + "(" + getExtent() + ")"; + } + @Override public BaseBiome getBiome(final Vector2D position) { return FaweCache.CACHE_BIOME[queue.getBiomeId(position.getBlockX(), position.getBlockZ())]; diff --git a/core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java b/core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java index c362c901..0ae705f0 100644 --- a/core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java +++ b/core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java @@ -58,6 +58,11 @@ public class NullExtent extends FaweRegionExtent { throw new FaweException(reason); } + @Override + public boolean setBlock(int x, int y, int z, BaseBlock block) throws WorldEditException { + throw new FaweException(reason); + } + @Override public BaseBlock getLazyBlock(int x, int y, int z) { throw new FaweException(reason); diff --git a/core/src/main/java/com/boydti/fawe/util/WEManager.java b/core/src/main/java/com/boydti/fawe/util/WEManager.java index ef68436c..3232792f 100644 --- a/core/src/main/java/com/boydti/fawe/util/WEManager.java +++ b/core/src/main/java/com/boydti/fawe/util/WEManager.java @@ -25,7 +25,10 @@ public class WEManager { try { final Field field = AbstractDelegateExtent.class.getDeclaredField("extent"); field.setAccessible(true); - field.set(parent, new NullExtent((Extent) field.get(parent), reason)); + Object currentExtent = field.get(parent); + if (!(currentExtent instanceof NullExtent)) { + field.set(parent, new NullExtent((Extent) field.get(parent), reason)); + } } catch (final Exception e) { MainUtil.handleError(e); } diff --git a/core/src/main/java/com/sk89q/worldedit/EditSession.java b/core/src/main/java/com/sk89q/worldedit/EditSession.java index 1dae298b..1788e400 100644 --- a/core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -420,7 +420,8 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting NullExtent nullExtent = new NullExtent(world, BBC.WORLDEDIT_CANCEL_REASON_MANUAL); while (traverser != null) { ExtentTraverser next = traverser.next(); - if (traverser.get() instanceof AbstractDelegateExtent) { + Extent get = traverser.get(); + if (get instanceof AbstractDelegateExtent && !(get instanceof NullExtent)) { traverser.setNext(nullExtent); } traverser = next; @@ -813,6 +814,11 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting return new HashMap<>(); } + @Override + public String toString() { + return super.toString() + ":" + extent.toString(); + } + /** * Get the number of blocks changed, including repeated block changes. * @@ -863,6 +869,7 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting @Override public BaseBlock getLazyBlock(final Vector position) { if (position.getY() > maxY || position.getY() < 0) { + if (!limit.MAX_FAILS()) throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS); return nullBlock; } return getLazyBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ()); @@ -879,6 +886,7 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting @Override public BaseBlock getBlock(final Vector position) { if (position.getY() > maxY || position.getY() < 0) { + if (!limit.MAX_FAILS()) throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS); return nullBlock; } return getLazyBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ()); @@ -1167,8 +1175,8 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting * * @param position the position * @param block the block - * @param probability a probability between 0 and 1, inclusive * @return whether a block was changed + * @param probability a probability between 0 and 1, inclusive * @throws MaxChangedBlocksException thrown if too many blocks are changed */ public boolean setChanceBlockIfAir(final Vector position, final BaseBlock block, final double probability) throws MaxChangedBlocksException { diff --git a/core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java b/core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java index cf5d5b70..c505ed67 100644 --- a/core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java +++ b/core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java @@ -181,6 +181,11 @@ public abstract class AbstractDelegateExtent implements LightingExtent { return null; } + @Override + public String toString() { + return super.toString() + ":" + extent.toString(); + } + @Override public final @Nullable Operation commit() { Operation ours = commitBefore(); diff --git a/core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java b/core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java index af8b64c4..2c32dadd 100644 --- a/core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java +++ b/core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java @@ -252,11 +252,12 @@ public class ForwardExtentCopy implements Operation { List entities = source.getEntities(region); for (int i = 0; i < repetitions; i++) { + Operations.completeBlindly(blockVisitor); + ExtentEntityCopy entityCopy = new ExtentEntityCopy(from, destination, to, currentTransform); entityCopy.setRemoving(removingEntities); EntityVisitor entityVisitor = new EntityVisitor(entities.iterator(), entityCopy); - Operations.completeBlindly(blockVisitor); Operations.completeBlindly(entityVisitor); if (transExt != null) { diff --git a/core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java b/core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java index ffdba211..80965575 100644 --- a/core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java +++ b/core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java @@ -24,6 +24,7 @@ import com.boydti.fawe.config.Settings; import com.boydti.fawe.example.MappedFaweQueue; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.HasFaweQueue; +import com.boydti.fawe.object.exception.FaweException; import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.Vector; @@ -159,12 +160,16 @@ public class RegionVisitor implements Operation { apply(trailIter.next()); apply(trailIter.next()); } + } catch (FaweException e) { + throw new RuntimeException(e); } catch (Throwable ignore) {} try { for (;;) { apply(trailIter.next()); apply(trailIter.next()); } + } catch (FaweException e) { + throw new RuntimeException(e); } catch (Throwable ignore) {} } else { for (Vector pt : iterable) {