fix: interpreter memory slicing overflow (#2506)

Upper bound could overflow to zero ever after `hasSize` check.

Issue only affects loads; tweaked code to match what's already done for
stores.

Fixes: #2505
This commit is contained in:
Nuno Cruces
2026-06-08 09:30:00 +01:00
committed by GitHub
parent 5500f5c252
commit b5671f1033
+2 -2
View File
@@ -342,7 +342,7 @@ func (m *MemoryInstance) readUint32Le(offset uint32) (uint32, bool) {
if !m.hasSize(offset, 4) { if !m.hasSize(offset, 4) {
return 0, false return 0, false
} }
return binary.LittleEndian.Uint32(m.Buffer[offset : offset+4]), true return binary.LittleEndian.Uint32(m.Buffer[offset:]), true
} }
// readUint64Le implements ReadUint64Le without using a context. This is extracted as both ints and floats are stored in // readUint64Le implements ReadUint64Le without using a context. This is extracted as both ints and floats are stored in
@@ -351,7 +351,7 @@ func (m *MemoryInstance) readUint64Le(offset uint32) (uint64, bool) {
if !m.hasSize(offset, 8) { if !m.hasSize(offset, 8) {
return 0, false return 0, false
} }
return binary.LittleEndian.Uint64(m.Buffer[offset : offset+8]), true return binary.LittleEndian.Uint64(m.Buffer[offset:]), true
} }
// writeUint32Le implements WriteUint32Le without using a context. This is extracted as both ints and floats are stored // writeUint32Le implements WriteUint32Le without using a context. This is extracted as both ints and floats are stored