diff --git a/test/tools/ossfuzz/protoToYul.cpp b/test/tools/ossfuzz/protoToYul.cpp index b81931b78..7025c3b9a 100644 --- a/test/tools/ossfuzz/protoToYul.cpp +++ b/test/tools/ossfuzz/protoToYul.cpp @@ -979,6 +979,8 @@ void ProtoConverter::visit(StoreFunc const& _x) void ProtoConverter::visit(ForStmt const& _x) { + if (++m_numForLoops > s_maxForLoops) + return; bool wasInGenericForBodyScope = m_inGenericForBodyScope; bool wasInForInit = m_inForInitScope; bool wasInBoundedForBodyScope = m_inBoundedForBodyScope; @@ -1020,6 +1022,9 @@ void ProtoConverter::visit(ForStmt const& _x) void ProtoConverter::visit(BoundedForStmt const& _x) { + if (++m_numForLoops > s_maxForLoops) + return; + // Boilerplate for loop that limits the number of iterations to a maximum of 4. std::string loopVarName("i_" + std::to_string(m_numNestedForLoops++)); m_output << "for { let " << loopVarName << " := 0 } " diff --git a/test/tools/ossfuzz/protoToYul.h b/test/tools/ossfuzz/protoToYul.h index ff6fbac13..0922b5aba 100644 --- a/test/tools/ossfuzz/protoToYul.h +++ b/test/tools/ossfuzz/protoToYul.h @@ -45,6 +45,7 @@ public: m_inForInitScope = false; m_inForCond = false; m_numNestedForLoops = 0; + m_numForLoops = 0; m_counter = 0; m_inputSize = 0; m_inFunctionDef = false; @@ -338,12 +339,16 @@ private: static unsigned constexpr s_modOutputParams = 5; /// Hard-coded identifier for a Yul object's data block static auto constexpr s_dataIdentifier = "datablock"; + /// Maximum number of for loops that a test case may contain + static auto constexpr s_maxForLoops = 2; /// Predicate to keep track of of the body of a generic for stmt. bool m_inGenericForBodyScope; /// Predicate to keep track of scope of the body of a bounded for stmt. bool m_inBoundedForBodyScope; // Index used for naming loop variable of bounded for loops unsigned m_numNestedForLoops; + /// Counter for number of for loops + unsigned m_numForLoops; /// Predicate to keep track of for loop init scope. If true, variable /// or function declarations can not be created. bool m_inForInitScope;