From 259a98b82c84d40714dc8f250092a572947f014f Mon Sep 17 00:00:00 2001 From: Bhargava Shastry Date: Mon, 3 Jan 2022 18:22:42 +0100 Subject: [PATCH] Impose stricter upper bound on memory accesses in order to prevent overflow/wrap around. --- test/tools/yulInterpreter/EVMInstructionInterpreter.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/tools/yulInterpreter/EVMInstructionInterpreter.cpp b/test/tools/yulInterpreter/EVMInstructionInterpreter.cpp index 1e030d098..067e00a9e 100644 --- a/test/tools/yulInterpreter/EVMInstructionInterpreter.cpp +++ b/test/tools/yulInterpreter/EVMInstructionInterpreter.cpp @@ -476,7 +476,9 @@ bool EVMInstructionInterpreter::accessMemory(u256 const& _offset, u256 const& _s { u256 newSize = (_offset + _size + 0x1f) & ~u256(0x1f); m_state.msize = max(m_state.msize, newSize); - return _size <= 0xffff; + // We only record accesses to contiguous memory chunks that are at most 0xffff bytes + // in size and at an offset of at most numeric_limits::max() - 0xffff + return _size <= 0xffff && _offset <= u256(numeric_limits::max() - 0xffff); } else m_state.msize = u256(-1);