Skip to content

Cannot open a file with O_TRUNC and O_APPEND #4376

@yagehu

Description

@yagehu

Describe the bug

This might be a wontfix but I figure I should report this anyway since out of all the runtimes I've tested only Wasmer and wasmi have this behavior. Native Linux also does not have this behavior.

Opening a file with O_TRUNC and O_APPEND together results in errno 28 inval. This is a result of the host-fs FileSystem uses Rust std::fs::OpenOptions, which performs this check.

I think Wasmtime doesn't have this behavior because it uses rustix which directly invokes the open syscall without this extra check.

$ zwasmer -vV; rustc -vV
wasmer 4.2.4 (0d782f1 2023-12-22)
binary: wasmer-cli
commit-hash: 0d782f18f99ba503f9aff89669c6ffd8e1631f53
commit-date: 2023-12-22
host: x86_64-unknown-linux-gnu
compiler: singlepass,cranelift
rustc 1.74.1 (a28077b28 2023-12-04)
binary: rustc
commit-hash: a28077b28a02b92985b3a3faecf92813155f1ea1
commit-date: 2023-12-04
host: x86_64-unknown-linux-gnu
release: 1.74.1
LLVM version: 17.0.4

Steps to reproduce

Compile the snippet with wasi-sdk and run with wasmer, mounting a directory.

#include <fcntl.h>
#include <stdio.h>

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

    return 0;
}

Expected behavior

It should create the file tmp/j and exit with no error.

Actual behavior

open: Invalid argument

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions