Repository navigation
Conversation
added 2 commits
October 20, 2026 12:22
WASI passes paths and other strings as a pointer and a length, and the guest does not have to NUL-terminate them. The trace lines in path_open, path_filestat_get, path_symlink, path_unlink_file, and fd_prestat_dir_name printed these with %s, so tracing a string that ends at the last byte of guest memory read past the buffer. Print each string with %.*s using the length that getMemPtr has already validated, clamped to INT_MAX. Add four spec tests under test/wasi that run with --trace. They cover strings that end at the last byte of memory, empty strings, and an embedded NUL. Three of them fail on the previous code. The embedded-nul test checks the NUL behavior that the fix keeps. Run them with python3 test/run-tests.py --bindir <dir> wasi on a WITH_WASI build.
path_open takes fs_rights_base and fs_rights_inheriting as i64 in the WASI ABI, but the interpreter read them with Get<u32>(). Debug builds asserted on the type mismatch under --trace, before any output was printed. Release builds read only the low 32 bits. Read both with Get<u64>().
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2890.
The WASI trace lines in
path_open,path_filestat_get,path_symlink,path_unlink_file, andfd_prestat_dir_nameprint guest strings with%s. Those strings are length-delimited and need not be NUL-terminated, so a string that ends at the last byte of guest memory is read past the buffer. Each string now prints with%.*sand the length thatgetMemPtralready validated, clamped toINT_MAX.The second commit changes
path_open'sfs_rights_baseandfs_rights_inheritingreads fromGet<u32>()toGet<u64>(). The WASI ABI declares both as i64. Debug builds asserted on the mismatch before tracing, so the new tests cannot run in Debug without it.The four tests in
test/wasi/trace-strings-*.txtrun with--trace. Onmain,end-memoryandzeroabort under ASan, andboundedprintsabcEXTRA.embedded-nulpasses on both trees. It guards the NUL behavior that this change keeps. The expected output ofzeroends some lines in a space, because an empty string prints nothing afterpath_open :.Tested:
WITH_WASI=ON,USE_ASAN=ON, clang, RelWithDebInfo and Debug:python3 test/run-tests.py --bindir <dir> wasipasses 9/9.main, same configurations: the four new tests fail as described above.BUILD_TESTS=ON:wabt-unittests138/138.run-tests.py2008 pass, 0 fail, 522 skipped, with per-test results identical tomain.clang-formatreports lines 622–626 ofinterp-wasi.cc. Those lines already fail onmainand this change does not touch them.The new tests do not run in upstream CI, which never builds
WITH_WASI. Run them withpython3 test/run-tests.py --bindir <dir> wasion aWITH_WASIbuild.