Skip to content

Commit 5111cad

Browse files
committed
fixup! [libevmasm] Add support to import evm assembly json.
1 parent f808b53 commit 5111cad

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
@@ -588,7 +588,24 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
588588
}
589589
else if (dataItem.isObject())
590590
{
591-
size_t index = static_cast<size_t>(std::stoi(dataItemID));
591+
size_t index{};
592+
try
593+
{
594+
// Using signed variant because stoul() still accepts negative numbers and
595+
// just lets them wrap around.
596+
int parsedDataItemID = std::stoi(dataItemID);
597+
solRequire(parsedDataItemID >= 0, AssemblyImportException, "The key '" + dataItemID + "' inside '.data' is out of the supported integer range.");
598+
index = static_cast<size_t>(parsedDataItemID);
599+
}
600+
catch (std::invalid_argument const&)
601+
{
602+
solThrow(AssemblyImportException, "The key '" + dataItemID + "' inside '.data' is not an integer.");
603+
}
604+
catch (std::out_of_range const&)
605+
{
606+
solThrow(AssemblyImportException, "The key '" + dataItemID + "' inside '.data' is out of the supported integer range.");
607+
}
608+
592609
if (result->m_subs.size() <= index)
593610
result->m_subs.resize(index + 1);
594611
std::shared_ptr<Assembly> subassembly(Assembly::fromJSON(dataItem, sourceList, _level + 1).first);

0 commit comments

Comments
 (0)