@@ -43,11 +43,14 @@ def type(type, arg)
4343 # Case: decoding array of string/bytes
4444 else
4545 l = Util . deserialize_big_endian_to_int arg [ 0 , 32 ]
46+ raise DecodingError , "Wrong data size for dynamic array" unless arg . size >= 32 + 32 * l
4647
4748 # Decode each element of the array
4849 ( 1 ..l ) . map do |i |
4950 pointer = Util . deserialize_big_endian_to_int arg [ i * 32 , 32 ] # Pointer to the size of the array's element
51+ raise DecodingError , "Offset out of bounds" if pointer < 32 * l || pointer > arg . size - 64
5052 data_l = Util . deserialize_big_endian_to_int arg [ 32 + pointer , 32 ] # length of the element
53+ raise DecodingError , "Offset out of bounds" if pointer + 32 + Util . ceil32 ( data_l ) > arg . size
5154 type ( Type . parse ( type . base_type ) , arg [ pointer + 32 , Util . ceil32 ( data_l ) + 32 ] )
5255 end
5356 end
@@ -74,9 +77,15 @@ def type(type, arg)
7477 nested_sub = type . nested_sub
7578
7679 if nested_sub . dynamic?
77- offsets = ( 0 ...l ) . map { |i | Util . deserialize_big_endian_to_int arg [ 32 + 32 * i , 32 ] }
80+ raise DecodingError , "Wrong data size for dynamic array" unless arg . size >= 32 + 32 * l
81+ offsets = ( 0 ...l ) . map do |i |
82+ off = Util . deserialize_big_endian_to_int arg [ 32 + 32 * i , 32 ]
83+ raise DecodingError , "Offset out of bounds" if off < 32 * l || off > arg . size - 64
84+ off
85+ end
7886 offsets . map { |off | type ( nested_sub , arg [ 32 + off ..] ) }
7987 else
88+ raise DecodingError , "Wrong data size for dynamic array" unless arg . size >= 32 + nested_sub . size * l
8089 # decoded dynamic-sized arrays with static sub-types
8190 ( 0 ...l ) . map { |i | type ( nested_sub , arg [ 32 + nested_sub . size * i , nested_sub . size ] ) }
8291 end
0 commit comments