Skip to content

Commit

Permalink
wasi: use proper param type for size in fd_filestat_set_size to h…
Browse files Browse the repository at this point in the history
…andle EFBIG (#1871)

Signed-off-by: Yage Hu <[email protected]>
  • Loading branch information
yagehu authored Dec 14, 2023
1 parent 87a48d8 commit 656d872
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions imports/wasi_snapshot_preview1/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,15 +464,15 @@ var fdFilestatSetSize = newHostFunc(wasip1.FdFilestatSetSizeName, fdFilestatSetS

func fdFilestatSetSizeFn(_ context.Context, mod api.Module, params []uint64) experimentalsys.Errno {
fd := int32(params[0])
size := uint32(params[1])
size := int64(params[1])

fsc := mod.(*wasm.ModuleInstance).Sys.FS()

// Check to see if the file descriptor is available
if f, ok := fsc.LookupFile(fd); !ok {
return experimentalsys.EBADF
} else {
return f.File.Truncate(int64(size))
return f.File.Truncate(size)
}
}

Expand Down
13 changes: 12 additions & 1 deletion imports/wasi_snapshot_preview1/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ func Test_fdFilestatSetSize(t *testing.T) {

tests := []struct {
name string
size uint32
size uint64
content, expectedContent []byte
expectedLog string
expectedErrno wasip1.Errno
Expand Down Expand Up @@ -881,6 +881,17 @@ func Test_fdFilestatSetSize(t *testing.T) {
expectedLog: `
==> wasi_snapshot_preview1.fd_filestat_set_size(fd=4,size=106)
<== errno=ESUCCESS
`,
},
{
name: "large size",
content: []byte(""),
expectedContent: []byte(""),
size: math.MaxUint64,
expectedErrno: wasip1.ErrnoInval,
expectedLog: `
==> wasi_snapshot_preview1.fd_filestat_set_size(fd=4,size=-1)
<== errno=EINVAL
`,
},
}
Expand Down

0 comments on commit 656d872

Please sign in to comment.