Skip to content

Commit

Permalink
Merge pull request from GHSA-544r-6qv4-wpfj
Browse files Browse the repository at this point in the history
Fix MemLoad - on top of v1.4.81.
  • Loading branch information
iulianpascalau authored Oct 31, 2023
2 parents a98a572 + b74ddf4 commit 5c7c2b2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion vmhost/contexts/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -1086,10 +1086,13 @@ func (context *runtimeContext) MemLoad(offset int32, length int32) ([]byte, erro
return nil, fmt.Errorf("mem load: %w", vmhost.ErrNegativeLength)
}

result := make([]byte, length)
var result []byte

if isRequestedEndTooLarge {
result = make([]byte, memoryLength-uint32(offset))
copy(result, memoryView[offset:])
} else {
result = make([]byte, requestedEnd-offset)
copy(result, memoryView[offset:requestedEnd])
}

Expand Down
2 changes: 1 addition & 1 deletion vmhost/contexts/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ func TestRuntimeContext_MemLoadCases(t *testing.T) {
length = 9
memContents, err = runtimeContext.MemLoad(offset, length)
require.Nil(t, err)
require.Equal(t, []byte{'e', 's', 't', ' ', 'd', 'a', 't', 'a', 0}, memContents)
require.Equal(t, []byte{'e', 's', 't', ' ', 'd', 'a', 't', 'a'}, memContents)

// Zero length
offset = int32(memory.Length() - 8)
Expand Down

0 comments on commit 5c7c2b2

Please sign in to comment.