mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #5926 from ethereum/inv-num-crash
Fix crash for too large struct array indicies
This commit is contained in:
commit
231cec56c6
@ -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).
|
||||
|
||||
|
||||
|
@ -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()))
|
||||
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
|
||||
solAssert(m_errorReporter.hasErrors(), "Expected errors as expectType returned false");
|
||||
|
||||
resultType = make_shared<TypeType>(make_shared<ArrayType>(
|
||||
DataLocation::Memory,
|
||||
typeType.actualType(),
|
||||
length->literalValue(nullptr)
|
||||
length
|
||||
));
|
||||
else
|
||||
m_errorReporter.fatalTypeError(index->location(), "Integer constant expected.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -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.
|
Loading…
Reference in New Issue
Block a user