From 6d40e11fe31e865a95e06cf3f8f7b44f195c44ce Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Sun, 21 Nov 2021 15:48:50 +0100 Subject: [PATCH] fix bound check in code chunking --- core/vm/instructions.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 27542af176..6902536758 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -389,12 +389,13 @@ func touchEachChunks(start, end uint64, code []byte, contract *Contract, evm *EV for chunk := start / 31; chunk <= end/31 && chunk <= uint64(len(code))/31; chunk++ { index := trieUtils.GetTreeKeyCodeChunk(contract.Address().Bytes(), uint256.NewInt(chunk)) count := uint64(0) + end := (chunk + 1) * 31 + // Look for the first code byte (i.e. no pushdata) - for ; count < 31 && !contract.IsCode(chunk*31+count); count++ { + for ; count < 31 && end+count < uint64(len(contract.Code)) && !contract.IsCode(chunk*31+count); count++ { } var value [32]byte value[0] = byte(count) - end := (chunk + 1) * 31 if end > uint64(len(code)) { end = uint64(len(code)) }