Skip to content

Commit

Permalink
Fix stack size overflow in NEI overlay handlers (#36)
Browse files Browse the repository at this point in the history
* Fix stack size overflow in NEI overlay handlers

* update gradle+bs+deps

* fix wci

---------

Co-authored-by: Martin Robertz <[email protected]>
  • Loading branch information
tth05 and Dream-Master authored Dec 3, 2023
1 parent 233f246 commit 13e0e65
Show file tree
Hide file tree
Showing 26 changed files with 348 additions and 147 deletions.
300 changes: 199 additions & 101 deletions build.gradle

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
dependencies {
api("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-217-GTNH:dev")
api("com.github.GTNewHorizons:NotEnoughItems:2.3.53-GTNH:dev")
implementation("com.github.GTNewHorizons:Baubles:1.0.1.16:dev")
implementation("com.github.GTNewHorizons:WirelessCraftingTerminal:1.9.0:dev")
api("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-291-GTNH:dev")
api("com.github.GTNewHorizons:NotEnoughItems:2.4.12-GTNH:dev")
implementation("com.github.GTNewHorizons:Baubles:1.0.2:dev")
implementation("com.github.GTNewHorizons:WirelessCraftingTerminal:1.10.1:dev")

compileOnly("com.github.GTNewHorizons:AE2FluidCraft-Rework:1.1.21-gtnh:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:Avaritiaddons:1.5.5-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:BuildCraftCompat:7.1.14:dev") { transitive = false }
compileOnly('com.github.GTNewHorizons:EnderIO:2.4.17:dev') {transitive=false}
compileOnly("com.github.GTNewHorizons:ForestryMC:4.6.7:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.43.50:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:GTplusplus:1.9.16:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:ThaumicEnergistics:1.4.3-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:Botania:1.9.23-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:AE2FluidCraft-Rework:1.1.67-gtnh:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:Avaritiaddons:1.6.0-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:BuildCraftCompat:7.1.16:dev") { transitive = false }
compileOnly('com.github.GTNewHorizons:EnderIO:2.5.6:dev') {transitive=false}
compileOnly("com.github.GTNewHorizons:ForestryMC:4.7.0:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.44.91:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:GTplusplus:1.10.34:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:ThaumicEnergistics:1.5.3-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:Botania:1.10.3-GTNH:dev") { transitive = false }
compileOnly("com.gregoriust.gregtech:gregtech_1.7.10:6.14.23:dev") { transitive = false }
compileOnly("curse.maven:thaumcraft-nei-plugin-225095:2241913") { transitive = false }
compileOnly("curse.maven:thermal-expansion-69163:2388759") { transitive = false }
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
7 changes: 4 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ done
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

Expand Down Expand Up @@ -197,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.github.vfyjxf.nee;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiWirelessCraftingTerminal;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.github.vfyjxf.nee.block.tile;

import java.util.*;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.IntStream;

import javax.annotation.Nonnull;
Expand All @@ -23,7 +27,12 @@
import appeng.api.networking.GridFlags;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.*;
import appeng.api.networking.crafting.CraftingItemList;
import appeng.api.networking.crafting.ICraftingCPU;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.networking.crafting.ICraftingProvider;
import appeng.api.networking.crafting.ICraftingProviderHelper;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkCraftingPatternChange;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.resources.I18n;
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import static com.github.vfyjxf.nee.processor.RecipeProcessor.NULL_IDENTIFIER;
import static com.github.vfyjxf.nee.utils.GuiUtils.isPatternTerm;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -163,7 +167,9 @@ private PacketNEIPatternRecipe packProcessRecipe(IRecipeHandler recipe, int reci
currentStack.stackSize = 1;
}

recipeInputs.setTag("#" + inputIndex, currentStack.writeToNBT(new NBTTagCompound()));
recipeInputs.setTag(
"#" + inputIndex,
ItemUtils.writeItemStackToNBT(currentStack, new NBTTagCompound()));
NEECraftingHandler.ingredients.put(INPUT_KEY + inputIndex, positionedStack);
inputIndex++;
}
Expand All @@ -181,7 +187,9 @@ private PacketNEIPatternRecipe packProcessRecipe(IRecipeHandler recipe, int reci
outputStack.stackSize = 1;
}

recipeOutputs.setTag(OUTPUT_KEY + outputIndex, outputStack.writeToNBT(new NBTTagCompound()));
recipeOutputs.setTag(
OUTPUT_KEY + outputIndex,
ItemUtils.writeItemStackToNBT(outputStack, new NBTTagCompound()));
outputIndex++;
}
break;
Expand Down Expand Up @@ -220,7 +228,7 @@ private PacketNEIPatternRecipe packCraftingTableRecipe(IRecipeHandler recipe, in
stack.setItemDamage(0);
}

recipeInputs.setTag("#" + slotIndex, stack.writeToNBT(new NBTTagCompound()));
recipeInputs.setTag("#" + slotIndex, ItemUtils.writeItemStackToNBT(stack, new NBTTagCompound()));
NEECraftingHandler.ingredients.put(INPUT_KEY + slotIndex, positionedStack);
}
}
Expand Down Expand Up @@ -249,7 +257,7 @@ private PacketArcaneRecipe packetArcaneRecipe(IRecipeHandler recipe, int recipeI
stack = currentStack.copy();
}
}
recipeInputs.setTag("#" + slotIndex, stack.writeToNBT(new NBTTagCompound()));
recipeInputs.setTag("#" + slotIndex, ItemUtils.writeItemStackToNBT(stack, new NBTTagCompound()));
}
}
return new PacketArcaneRecipe(recipeInputs);
Expand Down Expand Up @@ -282,7 +290,7 @@ private PacketExtremeRecipe packetExtremeRecipe(IRecipeHandler recipe, int recip
currentStack = stack.copy();
}
}
recipeInputs.setTag("#" + slotIndex, currentStack.writeToNBT(new NBTTagCompound()));
recipeInputs.setTag("#" + slotIndex, ItemUtils.writeItemStackToNBT(currentStack, new NBTTagCompound()));
}
return new PacketExtremeRecipe(recipeInputs);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package com.github.vfyjxf.nee.network;

import com.github.vfyjxf.nee.NotEnoughEnergistics;
import com.github.vfyjxf.nee.network.packet.*;
import com.github.vfyjxf.nee.network.packet.PacketArcaneRecipe;
import com.github.vfyjxf.nee.network.packet.PacketCraftingRequest;
import com.github.vfyjxf.nee.network.packet.PacketExtremeRecipe;
import com.github.vfyjxf.nee.network.packet.PacketNEIPatternRecipe;
import com.github.vfyjxf.nee.network.packet.PacketOpenCraftAmount;
import com.github.vfyjxf.nee.network.packet.PacketOpenGui;
import com.github.vfyjxf.nee.network.packet.PacketSetRecipe;
import com.github.vfyjxf.nee.network.packet.PacketSlotStackChange;
import com.github.vfyjxf.nee.network.packet.PacketStackCountChange;
import com.github.vfyjxf.nee.network.packet.PacketValueConfigClient;
import com.github.vfyjxf.nee.network.packet.PacketValueConfigServer;

import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

import com.github.vfyjxf.nee.utils.ItemUtils;

import appeng.container.slot.SlotFakeCraftingMatrix;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
Expand Down Expand Up @@ -50,7 +52,7 @@ public IMessage onMessage(PacketArcaneRecipe message, MessageContext ctx) {
NBTTagCompound currentStack;
for (int i = 0; i < recipeInput.length; i++) {
currentStack = (NBTTagCompound) message.input.getTag("#" + i);
recipeInput[i] = currentStack == null ? null : ItemStack.loadItemStackFromNBT(currentStack);
recipeInput[i] = currentStack == null ? null : ItemUtils.loadItemStackFromNBT(currentStack);
}

Field craftingSlots = ReflectionHelper.findField(ContainerKnowledgeInscriber.class, "craftingSlots");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

import com.github.vfyjxf.nee.utils.ItemUtils;

import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
Expand Down Expand Up @@ -58,7 +60,7 @@ public IMessage onMessage(PacketExtremeRecipe message, MessageContext ctx) {
NBTTagCompound currentStack;
for (int i = 0; i < recipeInputs.length; i++) {
currentStack = (NBTTagCompound) message.input.getTag("#" + i);
recipeInputs[i] = currentStack == null ? null : ItemStack.loadItemStackFromNBT(currentStack);
recipeInputs[i] = currentStack == null ? null : ItemUtils.loadItemStackFromNBT(currentStack);
}
int inputIndex = 0;
for (int i = 81; i < 162; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

import com.github.vfyjxf.nee.utils.ItemUtils;
import com.github.vfyjxf.nee.utils.ModIDs;
import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminal;
import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminalEx;
Expand Down Expand Up @@ -103,7 +104,7 @@ private void craftingTableRecipeHandler(AEBaseContainer container, PacketNEIPatt

for (int i = 0; i < recipeInput.length; i++) {
currentStack = (NBTTagCompound) message.input.getTag("#" + i);
recipeInput[i] = currentStack == null ? null : ItemStack.loadItemStackFromNBT(currentStack);
recipeInput[i] = currentStack == null ? null : ItemUtils.loadItemStackFromNBT(currentStack);
}

final IContainerCraftingPacket cct = (IContainerCraftingPacket) container;
Expand Down Expand Up @@ -150,12 +151,12 @@ private void processRecipeHandler(AEBaseContainer container, PacketNEIPatternRec

for (int i = 0; i < recipeInput.length; i++) {
NBTTagCompound currentStack = (NBTTagCompound) message.input.getTag("#" + i);
recipeInput[i] = currentStack == null ? null : ItemStack.loadItemStackFromNBT(currentStack);
recipeInput[i] = currentStack == null ? null : ItemUtils.loadItemStackFromNBT(currentStack);
}

for (int i = 0; i < recipeOutput.length; i++) {
NBTTagCompound currentStack = (NBTTagCompound) message.output.getTag(OUTPUT_KEY + i);
recipeOutput[i] = currentStack == null ? null : ItemStack.loadItemStackFromNBT(currentStack);
recipeOutput[i] = currentStack == null ? null : ItemUtils.loadItemStackFromNBT(currentStack);
}
if (inv != null && message.input != null && security != null) {
for (int i = 0; i < craftMatrix.getSizeInventory(); i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.github.vfyjxf.nee.processor;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.github.vfyjxf.nee.processor;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.github.vfyjxf.nee.processor;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.github.vfyjxf.nee.processor;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.github.vfyjxf.nee.processor;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.github.vfyjxf.nee.processor;

import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.github.vfyjxf.nee.processor;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.github.vfyjxf.nee.processor;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.github.vfyjxf.nee.processor;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.github.vfyjxf.nee.processor;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.github.vfyjxf.nee.processor;

import java.lang.reflect.Field;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;

Expand Down
Loading

0 comments on commit 13e0e65

Please sign in to comment.