@@ -93,6 +93,15 @@ type memoryWrapper struct {
9393
9494// slice returns the requested range of memory as a byte slice.
9595func (mw * memoryWrapper ) slice (begin , end int64 ) []byte {
96+ if end == begin {
97+ return []byte {}
98+ }
99+ if end < begin || begin < 0 {
100+ // TODO(karalabe): We can't js-throw from Go inside duktape inside Go. The Go
101+ // runtime goes belly up https://github.com/golang/go/issues/15639.
102+ log .Warn ("Tracer accessed out of bound memory" , "offset" , begin , "end" , end )
103+ return nil
104+ }
96105 if mw .memory .Len () < int (end ) {
97106 // TODO(karalabe): We can't js-throw from Go inside duktape inside Go. The Go
98107 // runtime goes belly up https://github.com/golang/go/issues/15639.
@@ -104,7 +113,7 @@ func (mw *memoryWrapper) slice(begin, end int64) []byte {
104113
105114// getUint returns the 32 bytes at the specified address interpreted as a uint.
106115func (mw * memoryWrapper ) getUint (addr int64 ) * big.Int {
107- if mw .memory .Len () < int (addr )+ 32 {
116+ if mw .memory .Len () < int (addr )+ 32 || addr < 0 {
108117 // TODO(karalabe): We can't js-throw from Go inside duktape inside Go. The Go
109118 // runtime goes belly up https://github.com/golang/go/issues/15639.
110119 log .Warn ("Tracer accessed out of bound memory" , "available" , mw .memory .Len (), "offset" , addr , "size" , 32 )
@@ -147,7 +156,7 @@ type stackWrapper struct {
147156
148157// peek returns the nth-from-the-top element of the stack.
149158func (sw * stackWrapper ) peek (idx int ) * big.Int {
150- if len (sw .stack .Data ()) <= idx {
159+ if len (sw .stack .Data ()) <= idx || idx < 0 {
151160 // TODO(karalabe): We can't js-throw from Go inside duktape inside Go. The Go
152161 // runtime goes belly up https://github.com/golang/go/issues/15639.
153162 log .Warn ("Tracer accessed out of bound stack" , "size" , len (sw .stack .Data ()), "index" , idx )
0 commit comments