Skip to content

Commit 711429d

Browse files
committed
fix: 🐛 Fixed unsafe network packet handling
1 parent bc4b4fb commit 711429d

5 files changed

Lines changed: 25 additions & 17 deletions

File tree

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ parchment_minecraft_version=1.21
88
parchment_mappings_version=2024.11.10
99
minecraft_version=1.21.1
1010
minecraft_version_range=[1.21.1,1.21.2)
11-
neo_version=21.1.129
12-
neo_version_range=[21.1.0,)
11+
neo_version=21.1.229
12+
neo_version_range=[21.1.229,)
1313
loader_version_range=[4,)
1414

1515
mod_id=sophisticatedcore
1616
mod_name=Sophisticated Core
1717
mod_license=All Rights Reserved
18-
mod_version=1.4.86
18+
mod_version=1.4.87
1919
mod_group_id=net.p3pp3rf1y
2020
mod_authors=P3pp3rF1y
2121
mod_description=A library / shared functionality mod for Sophisticated Storage and Backpacks
@@ -45,7 +45,7 @@ curios_version=9.5.1+1.21.1
4545
sawmill_cf_file_id=6119477
4646
moonlightlib_cf_file_id=6224057
4747
trashslot_version=21.1.2+1.21.1
48-
reliquary_version=[1.21.1-2.0.67,1.21.2)
48+
reliquary_version=[1.21.1-2.0.79,1.21.2)
4949
ftb_chunks_version=2101.1.11
5050
ftb_library_version=2101.1.21
5151
accessories_version=1.1.0-beta.52+1.21.1

src/main/java/net/p3pp3rf1y/sophisticatedcore/compat/recipeviewers/emi/EmiTransferRecipePayload.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121

2222
public record EmiTransferRecipePayload(ResourceLocation recipeId, ResourceLocation recipeTypeId, int action, List<Integer> slots, List<Integer> crafting,
2323
int output, List<ItemStack> stacks, boolean maxTransfer) implements CustomPacketPayload {
24+
private static final int MAX_CRAFTING_SLOTS = 9;
25+
private static final int MAX_INVENTORY_SLOTS = 512;
2426
public static final Type<EmiTransferRecipePayload> TYPE = new Type<>(SophisticatedCore.getRL("emi_transfer_recipe"));
2527
public static final StreamCodec<RegistryFriendlyByteBuf, EmiTransferRecipePayload> STREAM_CODEC = StreamCodecHelper.composite(ResourceLocation.STREAM_CODEC,
2628
EmiTransferRecipePayload::recipeId, ResourceLocation.STREAM_CODEC, EmiTransferRecipePayload::recipeTypeId, ByteBufCodecs.INT,
27-
EmiTransferRecipePayload::action, ByteBufCodecs.INT.apply(ByteBufCodecs.list()), EmiTransferRecipePayload::slots,
28-
ByteBufCodecs.INT.apply(ByteBufCodecs.list()), EmiTransferRecipePayload::crafting, ByteBufCodecs.INT, EmiTransferRecipePayload::output,
29-
ItemStack.OPTIONAL_LIST_STREAM_CODEC, EmiTransferRecipePayload::stacks, ByteBufCodecs.BOOL, EmiTransferRecipePayload::maxTransfer,
30-
EmiTransferRecipePayload::new);
29+
EmiTransferRecipePayload::action, ByteBufCodecs.INT.apply(ByteBufCodecs.list(MAX_INVENTORY_SLOTS)), EmiTransferRecipePayload::slots,
30+
ByteBufCodecs.INT.apply(ByteBufCodecs.list(MAX_CRAFTING_SLOTS)), EmiTransferRecipePayload::crafting, ByteBufCodecs.INT,
31+
EmiTransferRecipePayload::output, ItemStack.OPTIONAL_STREAM_CODEC.apply(ByteBufCodecs.list(MAX_CRAFTING_SLOTS)), EmiTransferRecipePayload::stacks,
32+
ByteBufCodecs.BOOL, EmiTransferRecipePayload::maxTransfer, EmiTransferRecipePayload::new);
3133

3234
@Override
3335
public Type<? extends CustomPacketPayload> type() {

src/main/java/net/p3pp3rf1y/sophisticatedcore/compat/recipeviewers/jei/JeiTransferRecipePayload.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616

1717
public record JeiTransferRecipePayload(ResourceLocation recipeId, ResourceLocation recipeTypeId, List<SlotTransfer> slotTransfers,
1818
List<Integer> craftingSlotIndexes, List<Integer> inventorySlotIndexes, boolean maxTransfer) implements CustomPacketPayload {
19+
private static final int MAX_CRAFTING_SLOTS = 9;
20+
private static final int MAX_INVENTORY_SLOTS = 512;
1921
public static final Type<JeiTransferRecipePayload> TYPE = new Type<>(SophisticatedCore.getRL("jei_transfer_recipe"));
2022
public static final StreamCodec<ByteBuf, JeiTransferRecipePayload> STREAM_CODEC = StreamCodec.composite(ResourceLocation.STREAM_CODEC,
2123
JeiTransferRecipePayload::recipeId, ResourceLocation.STREAM_CODEC, JeiTransferRecipePayload::recipeTypeId,
22-
SlotTransfer.STREAM_CODEC.apply(ByteBufCodecs.list()), JeiTransferRecipePayload::slotTransfers, ByteBufCodecs.INT.apply(ByteBufCodecs.list()),
23-
JeiTransferRecipePayload::craftingSlotIndexes, ByteBufCodecs.INT.apply(ByteBufCodecs.list()), JeiTransferRecipePayload::inventorySlotIndexes,
24-
ByteBufCodecs.BOOL, JeiTransferRecipePayload::maxTransfer, JeiTransferRecipePayload::new);
24+
SlotTransfer.STREAM_CODEC.apply(ByteBufCodecs.list(MAX_CRAFTING_SLOTS)), JeiTransferRecipePayload::slotTransfers,
25+
ByteBufCodecs.INT.apply(ByteBufCodecs.list(MAX_CRAFTING_SLOTS)), JeiTransferRecipePayload::craftingSlotIndexes,
26+
ByteBufCodecs.INT.apply(ByteBufCodecs.list(MAX_INVENTORY_SLOTS)), JeiTransferRecipePayload::inventorySlotIndexes, ByteBufCodecs.BOOL,
27+
JeiTransferRecipePayload::maxTransfer, JeiTransferRecipePayload::new);
2528

2629
@Override
2730
public Type<? extends CustomPacketPayload> type() {

src/main/java/net/p3pp3rf1y/sophisticatedcore/compat/recipeviewers/rei/ReiTransferRecipePayload.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@
3232

3333
public record ReiTransferRecipePayload(ResourceLocation recipeId, ResourceLocation recipeTypeId, CompoundTag tag, List<Integer> inputSlots,
3434
List<Integer> inventorySlots, boolean maxTransfer) implements CustomPacketPayload {
35+
private static final int MAX_CRAFTING_SLOTS = 9;
36+
private static final int MAX_INVENTORY_SLOTS = 512;
3537
public static final Type<ReiTransferRecipePayload> TYPE = new Type<>(SophisticatedCore.getRL("rei_move_items"));
3638
public static final StreamCodec<RegistryFriendlyByteBuf, ReiTransferRecipePayload> STREAM_CODEC = StreamCodec.composite(ResourceLocation.STREAM_CODEC,
3739
ReiTransferRecipePayload::recipeId, ResourceLocation.STREAM_CODEC, ReiTransferRecipePayload::recipeTypeId, ByteBufCodecs.COMPOUND_TAG,
38-
ReiTransferRecipePayload::tag, ByteBufCodecs.INT.apply(ByteBufCodecs.list()), ReiTransferRecipePayload::inputSlots,
39-
ByteBufCodecs.INT.apply(ByteBufCodecs.list()), ReiTransferRecipePayload::inventorySlots, ByteBufCodecs.BOOL, ReiTransferRecipePayload::maxTransfer,
40-
ReiTransferRecipePayload::new);
40+
ReiTransferRecipePayload::tag, ByteBufCodecs.INT.apply(ByteBufCodecs.list(MAX_CRAFTING_SLOTS)), ReiTransferRecipePayload::inputSlots,
41+
ByteBufCodecs.INT.apply(ByteBufCodecs.list(MAX_INVENTORY_SLOTS)), ReiTransferRecipePayload::inventorySlots, ByteBufCodecs.BOOL,
42+
ReiTransferRecipePayload::maxTransfer, ReiTransferRecipePayload::new);
4143

4244
@Override
4345
public Type<? extends CustomPacketPayload> type() {

src/main/java/net/p3pp3rf1y/sophisticatedcore/upgrades/cooking/CookingLogic.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import javax.annotation.Nullable;
3131

32+
import java.util.HashMap;
3233
import java.util.List;
3334
import java.util.Map;
3435
import java.util.Optional;
@@ -60,10 +61,10 @@ public class CookingLogic<T extends AbstractCookingRecipe> {
6061
private long remainingBurnTime = 0;
6162

6263
public static final Codec<Map<ResourceLocation, Integer>> RECIPES_USED_CODEC = Codec.unboundedMap(ResourceLocation.CODEC, ExtraCodecs.NON_NEGATIVE_INT);
64+
private static final int MAX_RECIPES_USED = 256;
6365

64-
public static final StreamCodec<FriendlyByteBuf, Map<ResourceLocation, Integer>> RECIPES_USED_STREAM_CODEC = StreamCodec.of(
65-
(buf, map) -> buf.writeMap(map, ResourceLocation.STREAM_CODEC, ByteBufCodecs.INT),
66-
buf -> buf.readMap(ResourceLocation.STREAM_CODEC, ByteBufCodecs.INT));
66+
public static final StreamCodec<FriendlyByteBuf, Map<ResourceLocation, Integer>> RECIPES_USED_STREAM_CODEC = ByteBufCodecs.map(HashMap::new,
67+
ResourceLocation.STREAM_CODEC, ByteBufCodecs.INT, MAX_RECIPES_USED);
6768

6869
public CookingLogic(ItemStack upgrade, Consumer<ItemStack> saveHandler, CookingUpgradeConfig cookingUpgradeConfig, RecipeType<T> recipeType,
6970
float burnTimeModifier) {

0 commit comments

Comments
 (0)