CapabilityProxy

CapabilityProxy

3M Downloads

Infinite loop in onBlockActivate

OneEyeMaker opened this issue ยท 3 comments

commented

Hello.
Firstly, thank you for your mods (and for this mod especially).
I've simple suggestion.
Capability proxy blocks (accidentally or intentionally) can be placed to form loops. And it can lead to infinite cycles and StackOverflowException (read: server crashes).
I suggest to add protection against such behavior.
It can be accomplished in 3 steps:

  1. Add similar method to code of TileCapabilityProxy:
public boolean isInLoop()
{
    BlockPos pos = getPos();
    TileEntity tileEntity = this;
    do
    {
        TileCapabilityProxy proxy = (TileCapabilityProxy) tileEntity;
        pos = proxy.getPos().offset(proxy.getOffset());
        tileEntity = proxy.getWorld().getTileEntity(pos);
    }
    while (tileEntity instanceof TileCapabilityProxy && !pos.equals(getPos()));
    return pos.equals(getPos());
}
  1. Call this method in BlockCapabilityProxy.onBlockActivated, TileCapabilityProxy.hasCapability, TileCapabilityProxy.getCapability. If this method return true, return false, false, null (respectively).
  2. Deactivate proxy block, if this method returns true.
commented

When exactly does the stackoverflow error occur? Can you send me the crashlog?
Because a stackoverflow protection actually already is in place.

commented

@rubensworks
Place 4 proxy blocks in loop and right-click one of them.
BlockCapabilityProxy.onBlockActivate just calls onBlockActivate of next proxy block (in loop) and this causes StackOverflowException.

Crash Report: https://pastebin.com/621eH87g

commented

Thanks, it looks like onBlockActivate is the only method that is not protected from stackoverflow, I missed that.