WasmEdge / WasmEdge

WasmEdge is a lightweight, high-performance, and extensible WebAssembly runtime for cloud native, edge, and decentralized applications. It powers serverless apps, embedded functions, microservices, smart contracts, and IoT devices.

Home Page:https://WasmEdge.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: (WASI) Failed to create directory with trailing backslash

ethanstanley3 opened this issue · comments

Summary

echo "`wasmedge -v` | `rustc -V` | `uname -m`"
wasmedge version 0.13.5 | rustc 1.76.0 (07dca489a 2024-02-04) | x86_64

Compiling a Rust test case to wasm32-wasi and running it with the WasmEdge CLI raises an exception, when the expected behavior is to succeed. The test case (shown below) is relatively simple. It attempts to create a new directory.

use std::fs;

fn main() {
    fs::create_dir("foo/").unwrap();
}

The test case runs successfully if the trailing slash in the directory name is omitted (foo/ is replaced with foo). The exception raised by the test case is ENOENT.

The 2018 edition of POSIX states that mkdir raises an ENOENT exception when "A component of the path prefix specified by path does not name an existing directory or path is an empty string", where a path prefix prefix is defined as "The part of a pathname up to, but not including, the last component and any trailing characters"

The path prefix of foo/ is the empty string, which does not contain components naming a non-existent directory. Therefore, a ENOENT exception should not be raised.

The test case runs successfully when given to other Wasm runtimes (Wasmtime, Wasmer, WAMR, and Wasmi) as well as when compiled to x86_64_unknown_linux_gnu and run natively.

This test case was derived from a program generated by Wasimilar, an Xsmith-based random program generator.

Current State

The test case fails to create a new directory and rasies an ENOENT exception.

Here is my observed output:

thread 'main' panicked at src/main.rs:4:28:
called `Result::unwrap()` on an `Err` value: Os { code: 44, kind: NotFound, message: "No such file or directory" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[2024-02-21 23:47:10.078] [error] execution failed: unreachable, Code: 0x89
[2024-02-21 23:47:10.078] [error]     In instruction: unreachable (0x00) , Bytecode offset: 0x00006b2a
[2024-02-21 23:47:10.078] [error]     When executing function name: "_start"

Expected State

The test case should create a directory, foo, without raising an exception.

Reproduction steps

Here is a zip file of a rust project that reproduces the behavior:
wasmedge-mkdir-bug.zip

  1. Unzip wasmedge-mkdir-bug.zip
  2. Go to wasmedge-mkdir-bug
  3. Compile with cargo build --target wasm32-wasi
  4. Run with wasmedge --dir=. target/wasm32-wasi/debug/wasmedge-mkdir-bug.wasm
  5. Observe that an exception is thrown with the message "No such file or directory"

Screenshots

No response

Any logs you want to share for showing the specific issue

No response

Components

CLI

WasmEdge Version or Commit you used

0.13.5

Operating system information

Ubuntu 22.04

Hardware Architecture

x86_64

Compiler flags and options

No response

Hi @ethanstanley3
Thanks for raising this; I will mark it as a good first issue so people can have a chance to fix it.

Hello, @hydai, I would like to take this up.

Assigned to you @tannal :-)