wasi: use proper param type for size in fd_filestat_set_size to handle EFBIG (#1871)

Signed-off-by: Yage Hu <me@huyage.dev>
This commit is contained in:
Yage Hu
2023-12-14 09:36:08 -08:00
committed by GitHub
parent 87a48d8eee
commit 656d872980
2 changed files with 14 additions and 3 deletions

View File

@@ -464,7 +464,7 @@ var fdFilestatSetSize = newHostFunc(wasip1.FdFilestatSetSizeName, fdFilestatSetS
func fdFilestatSetSizeFn(_ context.Context, mod api.Module, params []uint64) experimentalsys.Errno { func fdFilestatSetSizeFn(_ context.Context, mod api.Module, params []uint64) experimentalsys.Errno {
fd := int32(params[0]) fd := int32(params[0])
size := uint32(params[1]) size := int64(params[1])
fsc := mod.(*wasm.ModuleInstance).Sys.FS() fsc := mod.(*wasm.ModuleInstance).Sys.FS()
@@ -472,7 +472,7 @@ func fdFilestatSetSizeFn(_ context.Context, mod api.Module, params []uint64) exp
if f, ok := fsc.LookupFile(fd); !ok { if f, ok := fsc.LookupFile(fd); !ok {
return experimentalsys.EBADF return experimentalsys.EBADF
} else { } else {
return f.File.Truncate(int64(size)) return f.File.Truncate(size)
} }
} }

View File

@@ -835,7 +835,7 @@ func Test_fdFilestatSetSize(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
size uint32 size uint64
content, expectedContent []byte content, expectedContent []byte
expectedLog string expectedLog string
expectedErrno wasip1.Errno expectedErrno wasip1.Errno
@@ -881,6 +881,17 @@ func Test_fdFilestatSetSize(t *testing.T) {
expectedLog: ` expectedLog: `
==> wasi_snapshot_preview1.fd_filestat_set_size(fd=4,size=106) ==> wasi_snapshot_preview1.fd_filestat_set_size(fd=4,size=106)
<== errno=ESUCCESS <== 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
`, `,
}, },
} }