mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Stricter bounds for memory arrays.
This commit is contained in:
parent
f6d1cee06b
commit
150497c12a
@ -1663,7 +1663,22 @@ BoolResult ArrayType::validForLocation(DataLocation _loc) const
|
|||||||
{
|
{
|
||||||
case DataLocation::Memory:
|
case DataLocation::Memory:
|
||||||
{
|
{
|
||||||
bigint size = bigint(length()) * m_baseType->memoryHeadSize();
|
bigint size = bigint(length());
|
||||||
|
auto type = m_baseType;
|
||||||
|
while (auto arrayType = dynamic_cast<ArrayType const*>(type))
|
||||||
|
{
|
||||||
|
if (arrayType->isDynamicallySized())
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size *= arrayType->length();
|
||||||
|
type = arrayType->baseType();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (type->isDynamicallySized())
|
||||||
|
size *= type->memoryHeadSize();
|
||||||
|
else
|
||||||
|
size *= type->memoryDataSize();
|
||||||
if (size >= numeric_limits<unsigned>::max())
|
if (size >= numeric_limits<unsigned>::max())
|
||||||
return BoolResult::err("Type too large for memory.");
|
return BoolResult::err("Type too large for memory.");
|
||||||
break;
|
break;
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
contract C {
|
||||||
|
function f() public pure
|
||||||
|
{
|
||||||
|
bytes32[1263941234127518272][500] memory x;
|
||||||
|
uint[2**30][] memory y;
|
||||||
|
uint[2**30][2**30][] memory z;
|
||||||
|
uint[2**16][2**16][] memory w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (48-90): Type too large for memory.
|
||||||
|
// TypeError: (96-118): Type too large for memory.
|
||||||
|
// TypeError: (124-153): Type too large for memory.
|
||||||
|
// TypeError: (159-188): Type too large for memory.
|
@ -8,4 +8,4 @@ contract C {
|
|||||||
// TypeError: (26-66): Type too large for memory.
|
// TypeError: (26-66): Type too large for memory.
|
||||||
// TypeError: (96-116): Type too large for memory.
|
// TypeError: (96-116): Type too large for memory.
|
||||||
// TypeError: (146-173): Type too large for memory.
|
// TypeError: (146-173): Type too large for memory.
|
||||||
// TypeError: (203-230): Type too large for calldata.
|
// TypeError: (203-230): Type too large for memory.
|
||||||
|
Loading…
Reference in New Issue
Block a user