Merge pull request #5926 from ethereum/inv-num-crash

Fix crash for too large struct array indicies
This commit is contained in:
chriseth 2019-02-06 14:11:25 +01:00 committed by GitHub
commit 231cec56c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 8 deletions

View File

@ -4,6 +4,7 @@ Bugfixes:
* Code generator: Defensively pad allocation of creationCode and runtimeCode to multiples of 32 bytes.
* Parser: Disallow empty import statements.
* Type Checker: Dissallow mappings with data locations other than 'storage'
* Type Checker: Fix internal error when a struct array index does not fit into a uint256.
* Type system: Properly report packed encoded size for arrays and structs (mostly unused until now).

View File

@ -2205,15 +2205,22 @@ bool TypeChecker::visit(IndexAccess const& _access)
resultType = make_shared<TypeType>(make_shared<ArrayType>(DataLocation::Memory, typeType.actualType()));
else
{
expectType(*index, IntegerType::uint256());
if (auto length = dynamic_cast<RationalNumberType const*>(type(*index).get()))
resultType = make_shared<TypeType>(make_shared<ArrayType>(
DataLocation::Memory,
typeType.actualType(),
length->literalValue(nullptr)
));
u256 length = 1;
if (expectType(*index, IntegerType::uint256()))
{
if (auto indexValue = dynamic_cast<RationalNumberType const*>(type(*index).get()))
length = indexValue->literalValue(nullptr);
else
m_errorReporter.fatalTypeError(index->location(), "Integer constant expected.");
}
else
m_errorReporter.fatalTypeError(index->location(), "Integer constant expected.");
solAssert(m_errorReporter.hasErrors(), "Expected errors as expectType returned false");
resultType = make_shared<TypeType>(make_shared<ArrayType>(
DataLocation::Memory,
typeType.actualType(),
length
));
}
break;
}

View File

@ -0,0 +1,10 @@
contract test {
struct s { uint a; uint b;}
function f() pure public returns (byte) {
s[75555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555];
s[7];
}
}
// ----
// TypeError: (101-241): Type int_const 7555...(132 digits omitted)...5555 is not implicitly convertible to expected type uint256.