Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fd_fdstat_set_flags truncates file #1862

Closed
yagehu opened this issue Dec 12, 2023 · 1 comment · Fixed by #1863
Closed

fd_fdstat_set_flags truncates file #1862

yagehu opened this issue Dec 12, 2023 · 1 comment · Fixed by #1863
Labels
bug Something isn't working

Comments

@yagehu
Copy link
Contributor

yagehu commented Dec 12, 2023

Describe the bug
If a file is opened with oflags::trunc, a call to fd_fdstat_set_flags will truncate the file.

To Reproduce

Compile this snippet with wasi-sdk and run it:

clang wazero-write.c
mkdir -p tmp
wazero run -mount tmp a.out
stat tmp/a 
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>

int main(void) {
  int fd = open("tmp/a", O_RDWR | O_CREAT | O_TRUNC);
  if (fd == -1) {
    perror("open");
    return 1;
  }

  char * buf = "abc";

  int written = write(fd, buf, 3);

  printf("written %d\n", written);

  int fcntl_ret = fcntl(fd, F_SETFL, 0);
  if (fcntl_ret != 0) {
    perror("fcntl");
    return 1;
  }

  return 0;
}

Expected behavior
The file should be size 3 because we wrote 3 bytes to it. But it is size 0.

Environment (please complete the relevant information):

  • Go version: 1.21.4
  • wazero Version: 5796897f37852bf2042cd63959ce4ff673c4366e
  • Host architecture: amd64
  • Runtime mode: compiler

Additional context
Compiling the same snippet with native clang or gcc and running it will produce a 3-byte file as expected.

@yagehu yagehu added the bug Something isn't working label Dec 12, 2023
@evacchi
Copy link
Contributor

evacchi commented Dec 12, 2023

confirmed that even with other runtimes the byte size is still 3 after stat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants