Project Expansion

Project Expansion

4M Downloads

EMC Link Integer Overflow Bug

James103 opened this issue ยท 2 comments

commented

As of Project Expansion 1.16.5-1.0.18 for Minecraft 1.16.5, it is possible to get so much EMC so as to make it so the amount of the requested item you can afford rolls past 31 bits, causing a signed integer overflow and the following code to assume you don't have enough EMC since emc.divide(BigInteger.valueOf(cost)).intValue() < 1:

// give if item present & empty hand
IKnowledgeProvider provider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(owner);
long cost = ProjectEAPI.getEMCProxy().getValue(item);
BigInteger emc = provider.getEmc();
int count = emc.divide(BigInteger.valueOf(cost)).intValue();
if(count > item.getMaxStackSize()) count = item.getMaxStackSize();
if(count < 1) {
player.sendStatusMessage(new TranslationTextComponent("block.projectexpansion.emc_link.not_enough_emc", new StringTextComponent(String.valueOf(cost)).mergeStyle(TextFormatting.GREEN)).mergeStyle(TextFormatting.RED), true);
return ActionResultType.FAIL;
}

To reproduce:

  1. Give yourself a billion EMC: emc add @s 1000000000
  2. Place down an EMC Link and set it to output stone or any other item worth 1 EMC.
  3. Try to take items out of the EMC link.
  4. Repeat steps 1-3 until you get a not enough EMC error message.
commented

Just tested this myself and it does in fact prevent you from taking out the item(in this case im using stone)
image
image
image

commented

Fixed