Integrated Dynamics

Integrated Dynamics

63M Downloads

Counting a false Item carshes the server

druidbruce opened this issue ยท 1 comments

commented

Issue type:

  • ๐Ÿ› Bug

Short description:

if there exists an Item entry in [Item] that is false, then passing this list into itemListCount causes the server to crash.
this was tested in two environments, single player and server, both crashes the server.

  • induction 1(untested): if you try to add a size of an Item that is false to another Int, the server crashes
  • induction 2(untested, more general): if you try to access size of an Item that is false, the server crashes

Steps to reproduce the problem:

  1. make a zipWith operator that doesn't check list length
------make zipWith
zipWith :: (a -> (b -> c)) -> [a] -> [b] -> [c]

-- operators needed
map :: (a -> b) -> [a] -> [b]
flipPipe ::(b -> c) -> (a -> b) -> (a -> c)
expOpRes_2 :: (a -> (x -> y -> z)) -> (a -> x -> y -> z)
pipe_2 :: (x1 -> (x2 -> y)) -> (y -> r) -> (x1 -> x2 -> r)
get :: [a] -> Int -> a
rotate_2_4 :: (a -> (x -> y -> z -> d))  (a -> z -> y -> x -> d)
pipe_4ap4:: (a -> (x1 -> (x2 -> (x -> y)))) -> (y -> (x -> r)) -> (a -> x1 -> x2 -> x -> r) 
pipe_3 :: (a -> (x1 -> (x2 -> y))) -> (y -> r) -> (a -> x1 -> x2 -> r)
rotate_4_2_3 :: (A -> (a -> b -> c -> d)) -> (A -> c -> a -> b -> d)
ap :: (x -> (y -> r)) -> (x -> y) -> (x -> r)
buildList_Index :: [a] -> [Int]  -- given a list, returns a list of index of the given list
rotate_3_1_2 :: (a -> (b -> (c -> d))) -> (c -> a -> b -> d)

-- steps
fpM = flipPipe map :: (a -> (b -> c)) -> (a -> [b] -> [c])
m0 = expOpRes_2 fpM
m1 = flip m0 :: a -> (a -> (b -> c)) -> [b] -> [c]
m2 = pipe_2 get m1 :: [a] -> Int -> (a -> (b -> c)) -> [b] -> [c]
m3 = rotate_2_4 m2 :: [a] -> [b] -> (a -> (b -> c)) -> Int -> [c]
m4 = pipe_4ap4 m3 get :: [a] -> [b] -> (a -> (b -> c)) -> Int -> c
m5 = pipe_3 m4 map :: [a] -> [b] -> (a -> (b -> c)) -> [Int] -> [c]
m6 = rotate_4_2_3 m5 :: [a] -> [Int] -> [b] -> (a -> (b -> c)) -> [c]
m7 = ap m6 buildList_Index :: [a] -> [b] -> (a -> (b -> c)) -> [c]
zipWith = rotate_3_1_2 m7 :: (a -> (b -> c)) -> [a] -> [b] -> [c]
-- operators that is used that might have confusing names to what it is in the programmer
addition :: Num -> Num -> Num -- adds the two number
lazybuilt :: a -> (a -> a) -> [a]
len :: [a] -> Int -- gives the length of the list [a]
slice :: [a] -> Int(start) -> Int(end) -> [a] -- slices the list 

-- making the operators that is needed
flipPipe = flip pipe
expOpRes = flilpPipe apply
expOpRes_2 = flipPipe apply2
expOpRes_3 = flipPipe apply3
pipe_2(0) = flip (pipe flipPipe flipPipe)
pipe_2 = expOpRes (pipe_2(0) pipe_2(0) expOpRes)
pipe_3 = pipe_2 (flip (pipe flipPipe_2 flipPipe)) expOpRes_2
pipe_4 = pipe_2 (flip (pipe flipPipe_3 flipPipe)) expOpRes_3 
pipe^2 = expOpRes_2 (pipe_2 pipe pipe)
flipPipe_2 = flip pipe_2
flipPipe_3 = flip pipe_3
rotate_2_3 = pipe (pipe apply3 (apply flipPipe flip)) expOpRes_2
rotate_3_1_2 = pipe rotate_2_3 flip 
rotate_3_4 = pipe^2 expOpRes_3 (flipPipe_2 flip) expOpRes_3
rotate_4_2_3 = pipe (pipe rotate_3_4 rotate_2_3) expOpRes_3
rotate_2_4 = pipe rotate_4_2_3 rotate_3_4
applyTo_2 = pipe flip apply
combine = applyTo_2 ap id
pipe_4ap4 = pipe_2 (pipe_2 pipe_4 (applyTo_2 pipe_3 combine)) expOpRes_3
ap = rotate_3_1_2 pipe2 apply 
buildList_N = pipe addition (lazybuilt 0)
buildList_L_N = pipe buildList_N ((flip slice) 0)
buildList_Index = pipe len (buildList_L_N 1)
  1. apply itemw_size opeartor and two unequal length lists to zipWith

as seen from above step m7 for creating zipWith, the operator will iterate to the length of [a], meaning having a [a] that is longer than [b] will cause problems, whereas having [b] longer than [a] does nothing as the operator simply ignores the elements that are longer than [a]

so in this case, to create false Item, we have to make [a] longer than [b]

itemw_size :: Item -> Int -> Item  -- creates an Item that has size of Int (Item With Stacksize)
itemList_long :: a longer [Item]
intList_short :: a shorter [Int]
itemList_false = zipWith itemw_size itemList_long intList_short :: [Item]

now if we put itemList_false into a display panel, we should see that for the elements that itemList_long has but intList_short doesn't, it shows false, and those are the false items I have been referring to

  1. apply the [Item] with false card to itemListCount
itemListCount = item_list_count :: [Item] -> Item -> Int
map :: (a -> b) -> [a] -> [b] 
itemw_size :: Item -> Int -> Item 
pipe_2ap2 :: (a -> (x -> y)) -> (y -> (x -> d)) -> (a -> x -> d)
pipe_2ap2 = pipe_2 (pipe_2 (pipe_2 (pipe_2 pipe_2 rotate_2_3_1) combine) expOpRes) flip
rotate_2_3_1 :: (a -> (b -> (c -> d))) -> (b -> c -> a -> d)
rotate_2_3_1 = pipe rotate_3_1_2 rotate_3_1_2
-- used operators defined previously in step 1 when making zipWith

is0 = flip itemw_size :: Int -> Item -> Item 
is1 = pipe_2ap2 itemListCount is0 :: [Item] -> Item -> Item 
item_shuffle = pipe is1 map :: [Item(new)] -> [Item(reference)] -> [Item]

itemList_any :: a list of random Item

itemList_crash = item_shuffle itemList_false itemList_any :: [Item]

now displaying itemList_crash crashes the server.
it is true that itemList_crash isn't passed into the exact itemListCount operator, however its the core of the operator item_shuffle.

  1. it is inducted that directly using itemListCount would also crash
item_any :: any Item card 
int_crash = itemListCount itemList_false item_any :: Int 

int_crash would be likely to crash when shown in a display panel

  1. accessing the individual false elements of itemList_false with get and then size might also crash

Expected behaviour:

in step3, when displaying itemList_crash, it should just show error in the display panel instead of crashing
in step 4/5, displaying the final card should just give error


Versions:

  • This mod:
    IntegratedDynamics-1.16.5-1.7.2
    IntegratedTerminals-1.16.5-1.1.3
    IntegratedCrafting-1.16.5-1.0.13
    IntegratedTunnels-1.16.5-1.7.0
    CyclopsCore-1.16.5-1.11.4
    CommonCapabilities-1.16.5-2.5.6
  • Minecraft:
    1.16.5
  • Forge:
    36.1.2

Log file:

crash-2021-04-25_00.55.10-server.txt

commented

Thanks for reporting!