Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #52 from stealthrocket/fix-iovec-encoding
Browse files Browse the repository at this point in the history
wasicall: fix iovec encoding
  • Loading branch information
achille-roussel committed Jun 4, 2023
2 parents 2c75fa9 + dff2325 commit f3f61e0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/google/pprof v0.0.0-20230510103437-eeec1cb781c3
github.com/google/uuid v1.3.0
github.com/klauspost/compress v1.16.5
github.com/stealthrocket/wasi-go v0.3.0
github.com/stealthrocket/wasi-go v0.3.1-0.20230603195135-80f8c0d13ce3
github.com/stealthrocket/wazergo v0.19.0
github.com/stealthrocket/wzprof v0.1.5
github.com/tetratelabs/wazero v1.1.1-0.20230522055633-256b7a4bf970
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/d
github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/stealthrocket/wasi-go v0.3.0 h1:+L+DfnHkBmOkUmCbsyO9j1KPqsAFu426jD3HH/7BABc=
github.com/stealthrocket/wasi-go v0.3.0/go.mod h1:LBhZHvAroNNQTejkVTMJZ01ssj3jXF+3Lkbru4cTzGQ=
github.com/stealthrocket/wasi-go v0.3.1-0.20230603195135-80f8c0d13ce3 h1:rBxTTdWnXV5ZkNQDKKiV9tdPLdRYlCY0m0I6KaH+Uj4=
github.com/stealthrocket/wasi-go v0.3.1-0.20230603195135-80f8c0d13ce3/go.mod h1:LBhZHvAroNNQTejkVTMJZ01ssj3jXF+3Lkbru4cTzGQ=
github.com/stealthrocket/wazergo v0.19.0 h1:0ZBya2fBURvV+I2hGl0vcuQ8dgoUvllxQ7aYlZSA5nI=
github.com/stealthrocket/wazergo v0.19.0/go.mod h1:riI0hxw4ndZA5e6z7PesHg2BtTftcZaMxRcoiGGipTs=
github.com/stealthrocket/wzprof v0.1.5 h1:abEwQF9KtqV7UQ0hWk7431vul9/FxOg1eRCqwEKo9/4=
Expand Down
2 changes: 1 addition & 1 deletion internal/timemachine/wasicall/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ func encodeIOVecs(buffer []byte, iovecs []IOVec) []byte {
}

func encodeIOVecsPrefix(buffer []byte, iovecs []IOVec, size Size) []byte {
if size == 0 {
if int32(size) <= 0 {
return encodeU32(buffer, 0)
}
prefixCount := 0
Expand Down
56 changes: 56 additions & 0 deletions internal/timemachine/wasicall/codec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package wasicall

import (
"testing"

"github.com/stealthrocket/timecraft/internal/assert"
"github.com/stealthrocket/wasi-go"
)

func TestEncodeIOVecsPrefixSameSize(t *testing.T) {
v := wasi.IOVec("hello world")

encoded := encodeIOVecsPrefix(nil, []wasi.IOVec{v}, 11)
assert.Equal(t, len(encoded), 4+4+11)

decoded, leftover, err := decodeIOVecs(encoded, nil)
assert.OK(t, err)
assert.Equal(t, len(leftover), 0)
assert.DeepEqual(t, decoded, []wasi.IOVec{v})
}

func TestEncodeIOVecsPrefixShortSize(t *testing.T) {
v := wasi.IOVec("hello world")

encoded := encodeIOVecsPrefix(nil, []wasi.IOVec{v}, 5)
assert.Equal(t, len(encoded), 4+4+5)

decoded, leftover, err := decodeIOVecs(encoded, nil)
assert.OK(t, err)
assert.Equal(t, len(leftover), 0)
assert.DeepEqual(t, decoded, []wasi.IOVec{v[:5]})
}

func TestEncodeIOVecsPrefixZeroSize(t *testing.T) {
v := wasi.IOVec("hello world")

encoded := encodeIOVecsPrefix(nil, []wasi.IOVec{v}, 0)
assert.Equal(t, len(encoded), 4)

decoded, leftover, err := decodeIOVecs(encoded, nil)
assert.OK(t, err)
assert.Equal(t, len(leftover), 0)
assert.DeepEqual(t, decoded, ([]wasi.IOVec)(nil))
}

func TestEncodeIOVecsPrefixNegativeSize(t *testing.T) {
v := wasi.IOVec("hello world")

encoded := encodeIOVecsPrefix(nil, []wasi.IOVec{v}, ^wasi.Size(0))
assert.Equal(t, len(encoded), 4)

decoded, leftover, err := decodeIOVecs(encoded, nil)
assert.OK(t, err)
assert.Equal(t, len(leftover), 0)
assert.DeepEqual(t, decoded, ([]wasi.IOVec)(nil))
}

0 comments on commit f3f61e0

Please sign in to comment.