Skip to content

Commit ed4f888

Browse files
cameelr0qs
authored andcommitted
fixup! [libevmasm] Add support to import evm assembly json.
1 parent e90de7d commit ed4f888

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

libevmasm/Assembly.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,24 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
585585
}
586586
else if (dataItem.isObject())
587587
{
588-
size_t index = static_cast<size_t>(std::stoi(dataItemID));
588+
size_t index{};
589+
try
590+
{
591+
// Using signed variant because stoul() still accepts negative numbers and
592+
// just lets them wrap around.
593+
int parsedDataItemID = std::stoi(dataItemID);
594+
solRequire(parsedDataItemID >= 0, AssemblyImportException, "The key '" + dataItemID + "' inside '.data' is out of the supported integer range.");
595+
index = static_cast<size_t>(parsedDataItemID);
596+
}
597+
catch (std::invalid_argument const&)
598+
{
599+
solThrow(AssemblyImportException, "The key '" + dataItemID + "' inside '.data' is not an integer.");
600+
}
601+
catch (std::out_of_range const&)
602+
{
603+
solThrow(AssemblyImportException, "The key '" + dataItemID + "' inside '.data' is out of the supported integer range.");
604+
}
605+
589606
if (result->m_subs.size() <= index)
590607
result->m_subs.resize(index + 1);
591608
std::shared_ptr<Assembly> subassembly(Assembly::fromJSON(dataItem, sourceList, _level + 1).first);

0 commit comments

Comments
 (0)