Skip to content

add: add test for ABI decoding with invalid tuple offset #16017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion libsolidity/codegen/ABIFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ std::string ABIFunctions::tupleDecoder(TypePointers const& _types, bool _fromMem
}
)");
elementTempl("dynamic", decodingTypes[i]->isDynamicallyEncoded());
// TODO add test
elementTempl("revertString", revertReasonIfDebugFunction("ABI decoding: invalid tuple offset"));
elementTempl("load", _fromMemory ? "mload" : "calldataload");
elementTempl("values", boost::algorithm::join(valueNamesLocal, ", "));
Expand Down
18 changes: 18 additions & 0 deletions test/libsolidity/ABIDecoderTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,24 @@ BOOST_AUTO_TEST_CASE(complex_struct)
)
}

BOOST_AUTO_TEST_CASE(invalid_tuple_offset)
{
std::string sourceCode = R"(
contract C {
function f(uint[] calldata x) external pure returns (uint) {
return x.length > 0 ? x[0] : 0;
}
}
)";
BOTH_ENCODERS(
compileAndRun(sourceCode);
// Creating an invalid call with array offset pointing outside the calldata
bytes calldata = encodeArgs(0x20, 0xffff) + bytes(62, 0); // 0xffff is an invalid offset
// This should revert because the array offset is invalid
ABI_CHECK(callContractFunctionNoEncoding("f(uint256[])", calldata), encodeArgs());
)
}

BOOST_AUTO_TEST_SUITE_END()

} // end namespaces