Skip to content

Commit bc1df51

Browse files
committed
fixup! [libevmasm] Add support to import evm assembly json.
1 parent 61c68e6 commit bc1df51

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

0 commit comments

Comments
 (0)