Skip to content

Commit

Permalink
evm/memory: fix javascript loop index overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
cdump committed Dec 23, 2023
1 parent 4241138 commit 0cd8ff3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions evmole/evm/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def store(self, offset: int, value: bytes):

def load(self, offset: int) -> tuple[bytes, set[bytes]]:
res: list[tuple[int, bytes, bytes | None]] = [(0, b'\x00', None)] * 32
for i in range(offset, offset + 32):
idx = i - offset
for idx in range(32):
i = idx + offset
for off, seq, val in self._data:
if seq >= res[idx][0] and i >= off and i < off + len(val):
res[idx] = (seq, val[i - off : i - off + 1], val)
Expand Down
4 changes: 2 additions & 2 deletions js/src/evm/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export default class Memory {

load(offset) {
const res = new Array(32).fill([0, 0, undefined])
for (let i = offset; i < offset + 32; i++) {
const idx = i - offset
for (let idx = 0; idx < 32; idx++) {
const i = idx + offset
for (const [off, seq, val] of this._data) {
if (seq >= res[idx][0] && i >= off && i < off + val.length) {
res[idx] = [seq, val[i - off], val]
Expand Down

0 comments on commit 0cd8ff3

Please sign in to comment.