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

Read bytes bug ? #4856

Open
Userzxcvbvnm opened this issue Jun 17, 2024 · 0 comments
Open

Read bytes bug ? #4856

Userzxcvbvnm opened this issue Jun 17, 2024 · 0 comments
Assignees
Labels
bug Something isn't working 📦 lib-vfs About wasmer-vfs priority-high High priority issue

Comments

@Userzxcvbvnm
Copy link
Contributor

Userzxcvbvnm commented Jun 17, 2024

Describe the bug

Read bytes bug.

Steps to reproduce

(1)The test case is :


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/uio.h>

int get_fd(const char *filename, int flags) {
    int fd = open(filename, flags);
    
    if (fd == -1) {
        printf("Get file descriptor of file %s failed!\n", filename);
        return -1;
    } else {
        printf("Get file descriptor of file %s succeed!\n", filename);
        return fd;
    }
}

void closebyfd(int fd) {
    if (close(fd) == -1) {
        printf("Close the file %d by descriptor failed!\n", fd);
    }
}

void fd_read_00022_Ep05V(int fd) {
    printf("Enter function fd_read_00022_Ep05V\n");

    char buf1[1];
    char buf2[1];
    struct iovec iov[2];
    ssize_t num_read;

    iov[0].iov_base = buf1;
    iov[0].iov_len = 1;
    iov[1].iov_base = buf2;
    iov[1].iov_len = 1;

    num_read = readv(fd, iov, 2);

    if (num_read == -1) {
        printf("Error reading from file descriptor\n");
    } else {
        printf("Read %ld bytes using readv\n", num_read);
    }
}

int main() {
    int fd = get_fd("softfile_2", O_RDWR | O_TRUNC | O_CREAT);
    if (fd == -1) {
        return 1;
    }

    fd_read_00022_Ep05V(fd);

    closebyfd(fd);
    
    return 0;
}

(2)compile to wasm:./wasi-sdk-21.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-21.0/share/wasi-sysroot test.c -o test.wasm

(3)Running wasm:
(Before run the Wasm file, softfile_2 exists and softfile_2 is a softlink file points to subdir_1/subdir_4/subfile_2, subdir_1/subdir_4/subfile_2 exists and the file is 53 bytes.)
wasmer run --dir=. test.wasm

Expected behavior

print:

Get file descriptor of file softfile_2 succeed!
Enter function fd_read_00022_Ep05V
Read 2 bytes using readv

Actual behavior

wasmer print:

Get file descriptor of file softfile_2 succeed!
Enter function fd_read_00022_Ep05V
Read 0 bytes using readv

First, the file size is 53, wasmer open the file with O_TRUNC, the file is expected to be truced to 0 bytes, however, by checking with command line, we found the file is not trunced and remains 53 bytes.
However, the buffer size is 2 bytes, but 0 bytes are read.

Additional context

Ubuntu 20.04
x86_64
wasmer-4.3.1

@maminrayej maminrayej self-assigned this Jun 20, 2024
@maminrayej maminrayej added the 📦 lib-vfs About wasmer-vfs label Jun 20, 2024
@syrusakbary syrusakbary added bug Something isn't working priority-high High priority issue labels Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 📦 lib-vfs About wasmer-vfs priority-high High priority issue
Projects
None yet
Development

No branches or pull requests

3 participants