mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix array decoding offset overflow.
This commit is contained in:
parent
32b8332867
commit
72d0a56a72
@ -1187,19 +1187,14 @@ string ABIFunctions::abiDecodingFunctionArrayAvailableLength(ArrayType const& _t
|
|||||||
dst := add(array, 0x20)
|
dst := add(array, 0x20)
|
||||||
</dynamic>
|
</dynamic>
|
||||||
let src := offset
|
let src := offset
|
||||||
<?dynamicBase>
|
|
||||||
// TODO add check that we can actually load from all
|
|
||||||
// offset pointers, i.e. as below, but with stride being 0x20.
|
|
||||||
<!dynamicBase>
|
|
||||||
if gt(add(src, mul(length, <stride>)), end) {
|
if gt(add(src, mul(length, <stride>)), end) {
|
||||||
<revertInvalidStride>
|
<revertInvalidStride>
|
||||||
}
|
}
|
||||||
</dynamicBase>
|
|
||||||
for { let i := 0 } lt(i, length) { i := add(i, 1) }
|
for { let i := 0 } lt(i, length) { i := add(i, 1) }
|
||||||
{
|
{
|
||||||
<?dynamicBase>
|
<?dynamicBase>
|
||||||
let innerOffset := <load>(src)
|
let innerOffset := <load>(src)
|
||||||
// TODO add overflow check
|
if gt(innerOffset, 0xffffffffffffffff) { <revertStringOffset> }
|
||||||
let elementPos := add(offset, innerOffset)
|
let elementPos := add(offset, innerOffset)
|
||||||
<!dynamicBase>
|
<!dynamicBase>
|
||||||
let elementPos := src
|
let elementPos := src
|
||||||
@ -1218,11 +1213,11 @@ string ABIFunctions::abiDecodingFunctionArrayAvailableLength(ArrayType const& _t
|
|||||||
templ("dynamic", _type.isDynamicallySized());
|
templ("dynamic", _type.isDynamicallySized());
|
||||||
templ("load", _fromMemory ? "mload" : "calldataload");
|
templ("load", _fromMemory ? "mload" : "calldataload");
|
||||||
templ("dynamicBase", _type.baseType()->isDynamicallyEncoded());
|
templ("dynamicBase", _type.baseType()->isDynamicallyEncoded());
|
||||||
if (!_type.baseType()->isDynamicallyEncoded())
|
|
||||||
templ(
|
templ(
|
||||||
"revertInvalidStride",
|
"revertInvalidStride",
|
||||||
revertReasonIfDebug("ABI decoding: invalid calldata array stride")
|
revertReasonIfDebug("ABI decoding: invalid calldata array stride")
|
||||||
);
|
);
|
||||||
|
templ("revertStringOffset", revertReasonIfDebug("ABI decoding: invalid calldata array offset"));
|
||||||
templ("decodingFun", abiDecodingFunction(*_type.baseType(), _fromMemory, false));
|
templ("decodingFun", abiDecodingFunction(*_type.baseType(), _fromMemory, false));
|
||||||
return templ.render();
|
return templ.render();
|
||||||
});
|
});
|
||||||
|
@ -26,4 +26,4 @@ contract Test {
|
|||||||
// ====
|
// ====
|
||||||
// compileViaYul: also
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// test() -> 0x01e240
|
// test() -> FAILURE
|
||||||
|
@ -27,4 +27,4 @@ contract Test {
|
|||||||
// ====
|
// ====
|
||||||
// compileViaYul: also
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// withinArray() -> 0x03c480
|
// withinArray() -> FAILURE
|
||||||
|
@ -20,4 +20,4 @@ contract Test {
|
|||||||
// ====
|
// ====
|
||||||
// compileViaYul: also
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// test() -> 0x01e240
|
// test() -> FAILURE
|
||||||
|
Loading…
Reference in New Issue
Block a user