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

WASI panics in fd_readdir when trying to read a directory with the Cyrillic name Действие ("Action") #7006

Closed
XX opened this issue Sep 12, 2023 · 4 comments · Fixed by #7011
Assignees
Labels
bug Incorrect behavior in the current implementation that needs fixing

Comments

@XX
Copy link

XX commented Sep 12, 2023

I'm reading dir with subdirs from wasm WASI module. Some subdirs have names in Cyrillic. Most names work well, but a dir named Действие (translated as "Action") produces a panic:

thread 'tokio-runtime-worker' panicked at 'assertion failed: self.is_char_boundary(new_len)', /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/alloc/src/string.rs:1279:13
stack backtrace:
   0:     0x55c946fb46c1 - std::backtrace_rs::backtrace::libunwind::trace::he648b5c8dd376705
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x55c946fb46c1 - std::backtrace_rs::backtrace::trace_unsynchronized::h5da3e203eef39e9f
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x55c946fb46c1 - std::sys_common::backtrace::_print_fmt::h8d28d3f20588ae4c
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x55c946fb46c1 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd9a5b0c9c6b058c0
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x55c946fe282f - core::fmt::rt::Argument::fmt::h0afc04119f252b53
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/fmt/rt.rs:138:9
   5:     0x55c946fe282f - core::fmt::write::h50b1b3e73851a6fe
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/fmt/mod.rs:1094:21
   6:     0x55c946fb0377 - std::io::Write::write_fmt::h184eaf275e4484f0
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/io/mod.rs:1714:15
   7:     0x55c946fb44d5 - std::sys_common::backtrace::_print::hf58c3a5a25090e71
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x55c946fb44d5 - std::sys_common::backtrace::print::hb9cf0a7c7f077819
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x55c946fb5a03 - std::panicking::default_hook::{{closure}}::h066adb2e3f3e2c07
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:269:22
  10:     0x55c946fb5794 - std::panicking::default_hook::h277fa2776900ff14
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:288:9
  11:     0x55c946fb5f89 - std::panicking::rust_panic_with_hook::hceaf38da6d9db792
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:705:13
  12:     0x55c946fb5e41 - std::panicking::begin_panic_handler::{{closure}}::h2bce3ed2516af7df
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:595:13
  13:     0x55c946fb4b26 - std::sys_common::backtrace::__rust_end_short_backtrace::h090f3faf8f98a395
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:151:18
  14:     0x55c946fb5bd2 - rust_begin_unwind
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:593:5
  15:     0x55c943fe56a3 - core::panicking::panic_fmt::h4ec8274704d163a3
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/panicking.rs:67:14
  16:     0x55c943fe5733 - core::panicking::panic::hee69a8315e4031d6
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/panicking.rs:117:5
  17:     0x55c9443f35b5 - alloc::string::String::truncate::h82d02a6707fc8e5e
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/alloc/src/string.rs:1279:13
  18:     0x55c944014ebc - wasmtime_wasi::preview2::preview1::<impl wasmtime_wasi::preview2::preview1::wasi_snapshot_preview1::WasiSnapshotPreview1 for T>::fd_readdir::{{closure}}::{{closure}}::h97aab24454c0467a
                               at /home/xx/.cargo/git/checkouts/wasmtime-41807828cb3a7a7e/186c3ec/crates/wasi/src/preview2/preview1.rs:1614:17
  19:     0x55c944013582 - wasmtime_wasi::preview2::preview1::<impl wasmtime_wasi::preview2::preview1::wasi_snapshot_preview1::WasiSnapshotPreview1 for T>::fd_readdir::{{closure}}::h71c012aa997b73d6
                               at /home/xx/.cargo/git/checkouts/wasmtime-41807828cb3a7a7e/186c3ec/crates/wasi/src/preview2/preview1.rs:1512:5
  20:     0x55c9443e2fcd - <core::pin::Pin<P> as core::future::future::Future>::poll::hb4af1694529eb86d
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/future/future.rs:125:9
  21:     0x55c9440f07fd - wasmtime_wasi::preview2::preview1::wasi_snapshot_preview1::fd_readdir::{{closure}}::hf7116fbdd0addf6e
                               at /home/xx/.cargo/git/checkouts/wasmtime-41807828cb3a7a7e/186c3ec/crates/wasi/src/preview2/preview1.rs:409:1
  22:     0x55c9443ac11b - <tracing::instrument::Instrumented<T> as core::future::future::Future>::poll::h936b7cf29985876e
                               at /home/xx/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tracing-0.1.37/src/instrument.rs:272:9
  23:     0x55c944119dc9 - wasmtime_wasi::preview2::preview1::wasi_snapshot_preview1::add_to_linker::{{closure}}::{{closure}}::h63b0a11ab91ebc68
                               at /home/xx/.cargo/git/checkouts/wasmtime-41807828cb3a7a7e/186c3ec/crates/wasi/src/preview2/preview1.rs:409:1
  24:     0x55c9442febf6 - wasmtime::store::AsyncCx::block_on::h82bda0230fa2549f
                               at /home/xx/.cargo/git/checkouts/wasmtime-41807828cb3a7a7e/186c3ec/crates/wasmtime/src/store.rs:1939:17
  25:     0x55c9443d5257 - wasmtime::linker::Linker<T>::func_wrap5_async::{{closure}}::h9344d71184333eb2
                               at /home/xx/.cargo/git/checkouts/wasmtime-41807828cb3a7a7e/186c3ec/crates/wasmtime/src/linker.rs:165:32
  26:     0x55c94437a6cb - <F as wasmtime::func::IntoFunc<T,(wasmtime::func::Caller<T>,A1,A2,A3,A4,A5),R>>::into_func::native_call_shim::{{closure}}::{{closure}}::h3f9721c1a8eb8bfc
                               at /home/xx/.cargo/git/checkouts/wasmtime-41807828cb3a7a7e/186c3ec/crates/wasmtime/src/func.rs:1983:41
  27:     0x55c9441f5141 - core::ops::function::FnOnce::call_once::hce93171fad2be346
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/ops/function.rs:250:5
  28:     0x55c943fec4da - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::hba0591f268e936b6
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/panic/unwind_safe.rs:271:9
  29:     0x55c944195178 - std::panicking::try::do_call::hb281efb5695617a3
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:500:40
  30:     0x55c9441a752b - __rust_try
  31:     0x55c944185419 - std::panicking::try::h6b63c45588efcce6
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:464:19
  32:     0x55c9441bc2fd - std::panic::catch_unwind::h64a7c0ca6df50084
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panic.rs:142:14
  33:     0x55c9443791ee - <F as wasmtime::func::IntoFunc<T,(wasmtime::func::Caller<T>,A1,A2,A3,A4,A5),R>>::into_func::native_call_shim::{{closure}}::h9fdd439159cc9c6d
                               at /home/xx/.cargo/git/checkouts/wasmtime-41807828cb3a7a7e/186c3ec/crates/wasmtime/src/func.rs:1978:29
  34:     0x55c94438911b - wasmtime::func::Caller<T>::with::{{closure}}::h5736c62974799fb0
                               at /home/xx/.cargo/git/checkouts/wasmtime-41807828cb3a7a7e/186c3ec/crates/wasmtime/src/func.rs:1778:13
  35:     0x55c94432c7e3 - wasmtime_runtime::instance::Instance::from_vmctx::hc0687768455fff47
                               at /home/xx/.cargo/git/checkouts/wasmtime-41807828cb3a7a7e/186c3ec/crates/runtime/src/instance.rs:240:9
  36:     0x55c944386701 - wasmtime::func::Caller<T>::with::h54bd907b8742a763
                               at /home/xx/.cargo/git/checkouts/wasmtime-41807828cb3a7a7e/186c3ec/crates/wasmtime/src/func.rs:1776:9
  37:     0x55c944378063 - <F as wasmtime::func::IntoFunc<T,(wasmtime::func::Caller<T>,A1,A2,A3,A4,A5),R>>::into_func::native_call_shim::h4d07b8819148efa0
                               at /home/xx/.cargo/git/checkouts/wasmtime-41807828cb3a7a7e/186c3ec/crates/wasmtime/src/func.rs:1967:34

Versions and Environment

Wasmtime version or commit: actual from master branch
Operating system: Kubuntu
Architecture: x86_64 GNU/Linux

@XX XX added the bug Incorrect behavior in the current implementation that needs fixing label Sep 12, 2023
@bjorn3
Copy link
Contributor

bjorn3 commented Sep 12, 2023

This is the issue I think

path.truncate(cap);
path is a string, so not every length of truncation would leave behind a valid UTF-8 string. The truncation should probably be done on a Vec<u8> instead.

@alexcrichton
Copy link
Member

Thanks for tracking this down @bjorn3!

I believe this should be fixed by #7011, but @XX can you test and confirm?

@XX
Copy link
Author

XX commented Sep 13, 2023

@alexcrichton I built the app with your fix ( #7011 ) and all directories are processed well. Thank You!

@pchickey
Copy link
Contributor

Thanks for the report @XX and thanks for the fix @alexcrichton !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior in the current implementation that needs fixing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants