Skip to content

Commit

Permalink
Fix jumpdest offset overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Nov 27, 2019
1 parent e6f6421 commit 53a5808
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/evmone/analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ code_analysis analyze(evmc_revision rev, const uint8_t* code, size_t code_size)
{
// The JUMPDEST is always the first instruction in the block.
// We don't have to insert anything to the instruction table.
analysis.jumpdest_offsets.emplace_back(static_cast<int16_t>(code_pos - code - 1));
analysis.jumpdest_offsets.emplace_back(static_cast<int32_t>(code_pos - code - 1));
analysis.jumpdest_targets.emplace_back(
static_cast<int16_t>(analysis.instrs.size() - 1));
static_cast<int32_t>(analysis.instrs.size() - 1));
}
else
analysis.instrs.emplace_back(opcode_info.fn);
Expand Down
4 changes: 2 additions & 2 deletions lib/evmone/analysis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ struct code_analysis
/// The offsets of JUMPDESTs in the original code.
/// These are values that JUMP/JUMPI receives as an argument.
/// The elements are sorted.
std::vector<int16_t> jumpdest_offsets;
std::vector<int32_t> jumpdest_offsets;

/// The indexes of the instructions in the generated instruction table
/// matching the elements from jumdest_offsets.
/// This is value to which the next instruction pointer must be set in JUMP/JUMPI.
std::vector<int16_t> jumpdest_targets;
std::vector<int32_t> jumpdest_targets;
};

inline int find_jumpdest(const code_analysis& analysis, int offset) noexcept
Expand Down
2 changes: 1 addition & 1 deletion test/utils/dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void dump(const evmone::code_analysis& analysis)
if (static_cast<size_t>(analysis.jumpdest_targets[t]) == index)
return analysis.jumpdest_offsets[t];
}
return int16_t{-1};
return int32_t{-1};
};

std::cout << "";
Expand Down

0 comments on commit 53a5808

Please sign in to comment.