From bb9d694a6a6ef18947d17bd914af800b60c7e652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Thu, 19 Dec 2024 16:33:40 +0100 Subject: [PATCH] Assembly: Fix check for the maximum size of the EOF data section --- libevmasm/Assembly.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp index 17c4ee10e741..430124e2adad 100644 --- a/libevmasm/Assembly.cpp +++ b/libevmasm/Assembly.cpp @@ -1683,8 +1683,12 @@ LinkerObject const& Assembly::assembleEOF() const // DATALOADN loads 32 bytes from EOF data section zero padded if reading out of data bounds. // In our case we do not allow DATALOADN with offsets which reads out of data bounds. auto const staticAuxDataSize = maxAuxDataLoadNOffset.has_value() ? (*maxAuxDataLoadNOffset + 32u) : 0u; - solRequire(preDeployDataSectionSize + staticAuxDataSize < std::numeric_limits::max(), AssemblyException, - "Invalid DATALOADN offset."); + auto const preDeployAndStaticAuxDataSize = preDeployDataSectionSize + staticAuxDataSize; + solRequire( + preDeployAndStaticAuxDataSize <= std::numeric_limits::max(), + AssemblyException, + "Invalid DATALOADN offset." + ); // If some data was already added to data section we need to update data section refs accordingly if (preDeployDataSectionSize > 0) @@ -1695,8 +1699,6 @@ LinkerObject const& Assembly::assembleEOF() const setBigEndianUint16(ret.bytecode, refPosition, staticAuxDataOffset + preDeployDataSectionSize); } - auto const preDeployAndStaticAuxDataSize = preDeployDataSectionSize + staticAuxDataSize; - setBigEndianUint16(ret.bytecode, dataSectionSizePosition, preDeployAndStaticAuxDataSize); return ret;