You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A fuzzing campaign for the ABI decoder revealed several crashes. This finding serves as an umbrella finding to list all the different crashes we observed. The harness for the fuzzer is shown in the following figure.
The findings are relevant for use cases where untrusted ABI definitions are parsed. All the findings below are due to malformed type definitions. These types are not controlled by Sway programs, but by the compiler which emits an ABI definition.
This finding is Undetermined because it was not part of the initial scope.
Division of zero
The following unit test panics with attempt to calculate the remainder with a divisor of zero at fuels-rs/packages/fuels-core/src/types/param_types.rs:76.
The following test crashes with a stack overflow. It is possible to construct deeply nested ParamTypes which when consumed by the parser cause a stack overflow. Depending on the system configuration it might be required to change the 13500 in order to witness the crash.
The stack overflow here is caused by fuels-rs/packages/fuels-core/src/codec/abi_decoder.rs:60-63.
Figure 32.7: Unit test that crashes with a stack overflow.
#[test]pubfnstack_overflow(){usecrate::types::param_types::ParamType;usecrate::types::param_types::ParamType::*;letmut typ:ParamType = U16;for _ in0..13500{
typ = Vector(Box::new(typ));}fuzz_abi_decode(&[8,9,9,9,9,9,9,9],
typ
);}
Memory allocation
The following unit test can panic with a failed memory allocation at fuels-rs/packages/fuels-core/src/codec/abi_decoder.rs:138. This is related to the “Capacity overflow” already mentioned in this finding. If the array length is lower than the same attack vector might lead to a hang of the parser. If it is higher, then it might lead to a capacity overflow like described above.
Figure 32.8: Unit test that crashed due to large memory allocation.
Short term, avoid panicing by handling the errors appropriately. For the stack overflows, make sure to avoid recursive calls and instead implement parsing iteratively. Also, setup reasonable length limits for types which include a length like Arrays.
Long term, deploy a fuzzer for the ABI decoding parser. The above fuzz harness can be used together with Trail of Bit’s test-fuzz fuzzer. The instructions for setting it up can be found in the documentation of the project.
The text was updated successfully, but these errors were encountered:
Description
A fuzzing campaign for the ABI decoder revealed several crashes. This finding serves as an umbrella finding to list all the different crashes we observed. The harness for the fuzzer is shown in the following figure.
Figure 32.1: Fuzz harness
The findings are relevant for use cases where untrusted ABI definitions are parsed. All the findings below are due to malformed type definitions. These types are not controlled by Sway programs, but by the compiler which emits an ABI definition.
This finding is Undetermined because it was not part of the initial scope.
Division of zero
The following unit test panics with attempt to calculate the remainder with a divisor of zero at fuels-rs/packages/fuels-core/src/types/param_types.rs:76.
Figure 32.2: Unit test that panics
Attempt to multiply with overflow
The following test panics at fuels-rs/packages/fuels-core/src/codec/abi_decoder.rs:256 with attempt to multiply with overflow.
Figure 32.3: Unit test that panics
The next panic is caused by fuels-rs/packages/fuels-core/src/types/param_types.rs:76.
Figure 32.4: Unit test that panics
The next unit tests panics at fuels-rs/packages/fuels-core/src/types/param_types.rs:155.
Figure 32.5: Unit test that panics
Capacity overflow
The following unit tests panics with the message capacity overflow at fuels-rs/packages/fuels-core/src/codec/abi_decoder.rs:138.
Figure 32.6: Unit test that panics
Stack overflow
The following test crashes with a stack overflow. It is possible to construct deeply nested ParamTypes which when consumed by the parser cause a stack overflow. Depending on the system configuration it might be required to change the 13500 in order to witness the crash.
The stack overflow here is caused by fuels-rs/packages/fuels-core/src/codec/abi_decoder.rs:60-63.
Figure 32.7: Unit test that crashes with a stack overflow.
Memory allocation
The following unit test can panic with a failed memory allocation at fuels-rs/packages/fuels-core/src/codec/abi_decoder.rs:138. This is related to the “Capacity overflow” already mentioned in this finding. If the array length is lower than the same attack vector might lead to a hang of the parser. If it is higher, then it might lead to a capacity overflow like described above.
Figure 32.8: Unit test that crashed due to large memory allocation.
Recommendations
Short term, avoid panicing by handling the errors appropriately. For the stack overflows, make sure to avoid recursive calls and instead implement parsing iteratively. Also, setup reasonable length limits for types which include a length like Arrays.
Long term, deploy a fuzzer for the ABI decoding parser. The above fuzz harness can be used together with Trail of Bit’s test-fuzz fuzzer. The instructions for setting it up can be found in the documentation of the project.
The text was updated successfully, but these errors were encountered: