Skip to content
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
10 changes: 10 additions & 0 deletions libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3634,7 +3634,17 @@ bool TypeChecker::visit(IndexAccess const& _access)
if (expectType(*index, *TypeProvider::uint256()))
{
if (auto indexValue = dynamic_cast<RationalNumberType const*>(type(*index)))
{
// Mirror the zero-length rejection from
// DeclarationTypeChecker::endVisit(ArrayTypeName). Static array types
// written as expressions (e.g. inside `abi.decode((T[0][]))`) never
// go through that visitor, so without this guard the zero-length
// element type propagates to codegen and triggers an ICE in
// callers that assume `calldataStride() > 0`.
if (indexValue->value() == 0)
m_errorReporter.fatalTypeError(1406_error, index->location(), "Array with zero length specified.");
length = indexValue->literalValue(nullptr);
}
else
m_errorReporter.fatalTypeError(3940_error, index->location(), "Integer constant expected.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Used to cause ICE in ABIFunctions::abiDecodingFunctionArrayAvailableLength
// when a dynamic array's element type was a zero-length static array.
contract C {
function f(bytes memory b) public pure {
abi.decode(b, (uint256[0][]));
}
}
// ----
// TypeError 1406: (146-147): Array with zero length specified.