Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/orchestrator/pkg/sandbox/block/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ func (c *Cache) sliceDirect(off, length int64) ([]byte, error) {
return nil, nil
}

if off < 0 || off >= c.size {
return nil, BytesNotAvailableError{}
}

end := min(off+length, c.size)

return (*c.mmap)[off:end], nil
Expand Down
14 changes: 14 additions & 0 deletions packages/orchestrator/pkg/sandbox/block/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@ func TestCopyFromProcess_HugepageToRegularPage(t *testing.T) {
require.NoError(t, compareData(data[:n], mem[pageSize*4:pageSize*8]))
}

func TestSliceDirectOutOfBoundsReturnsBytesNotAvailable(t *testing.T) {
t.Parallel()

cache, err := NewCache(16, 4, t.TempDir()+"/cache", false)
require.NoError(t, err)
t.Cleanup(func() { _ = cache.Close() })

_, err = cache.sliceDirect(16, 4)
require.ErrorIs(t, err, BytesNotAvailableError{})

_, err = cache.sliceDirect(32, 4)
require.ErrorIs(t, err, BytesNotAvailableError{})
}

func TestEmptyRanges(t *testing.T) {
t.Parallel()

Expand Down
Loading