Skip to content

Commit

Permalink
[29.0.x]: Fix a missing increment in p1-to-p2 adapter (#10067)
Browse files Browse the repository at this point in the history
* Add audit for `wasmtime-math` (#10059)

I noticed that CI is failing given that an audit and policy for
`wasmtime-math` is missing.

`wasmtime-math` was introduced in
https://github.com/bytecodealliance/wasmtime/pull/9808/files.

I followed a similar approach to what it's used for all the other
`wasmtime-*` crates.

* Fix a missing increment in p1-to-p2 adapter (#10064)

This commit fixes a bug in the WASIp1-to-WASIp2 adapter during
`fd_prestat_dir_name` where an iterator variable was forgotten to be
incremented. That means that getting the path for anything other than
the first preopen didn't work correctly.

Closes #10058

* Downgrade `wasip2` dep to 0.13.0

Compat with 1.81.0 MSRV

---------

Co-authored-by: Saúl Cabrera <[email protected]>
  • Loading branch information
alexcrichton and saulecabrera authored Jan 21, 2025
1 parent 5454077 commit e304726
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 5 deletions.
29 changes: 24 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/test-programs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ futures = { workspace = true, default-features = false, features = ['alloc'] }
url = { workspace = true }
sha2 = "0.10.2"
base64 = "0.21.0"
wasip2 = { version = "0.13.0", package = 'wasi' }
29 changes: 29 additions & 0 deletions crates/test-programs/src/bin/cli_multiple_preopens.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::str;

fn main() {
dbg!(wasip2::filesystem::preopens::get_directories());
unsafe {
let p3 = wasi::fd_prestat_get(3).unwrap();
let p4 = wasi::fd_prestat_get(4).unwrap();
let p5 = wasi::fd_prestat_get(5).unwrap();
assert_eq!(wasi::fd_prestat_get(6).err().unwrap(), wasi::ERRNO_BADF);

assert_eq!(p3.u.dir.pr_name_len, 2);
assert_eq!(p4.u.dir.pr_name_len, 2);
assert_eq!(p5.u.dir.pr_name_len, 2);

let mut buf = [0; 100];

wasi::fd_prestat_dir_name(3, buf.as_mut_ptr(), buf.len()).unwrap();
assert_eq!(str::from_utf8(&buf[..2]).unwrap(), "/a");
wasi::fd_prestat_dir_name(4, buf.as_mut_ptr(), buf.len()).unwrap();
assert_eq!(str::from_utf8(&buf[..2]).unwrap(), "/b");
wasi::fd_prestat_dir_name(5, buf.as_mut_ptr(), buf.len()).unwrap();
assert_eq!(str::from_utf8(&buf[..2]).unwrap(), "/c");
assert_eq!(
wasi::fd_prestat_dir_name(6, buf.as_mut_ptr(), buf.len()),
Err(wasi::ERRNO_BADF),
);
}
// ..
}
1 change: 1 addition & 0 deletions crates/wasi-preview1-component-adapter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ impl ImportAlloc {
ImportAlloc::GetPreopenPath { cur, nth, alloc } => {
if align == 1 {
let real_alloc = *nth == *cur;
*cur += 1;
if real_alloc {
alloc.alloc(align, size)
} else {
Expand Down
14 changes: 14 additions & 0 deletions supply-chain/audits.toml
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,14 @@ start = "2022-11-21"
end = "2025-07-30"
notes = "The Bytecode Alliance is the author of this crate."

[[wildcard-audits.wasmtime-math]]
who = "Saúl Cabrera <[email protected]>"
criteria = "safe-to-deploy"
user-id = 73222 # wasmtime-publish
start = "2025-01-20"
end = "2026-01-21"
notes = "The Bytecode Alliance is the author of this crate."

[[wildcard-audits.wasmtime-runtime]]
who = "Bobby Holley <[email protected]>"
criteria = "safe-to-deploy"
Expand Down Expand Up @@ -4457,6 +4465,12 @@ user-id = 1 # Alex Crichton (alexcrichton)
start = "2020-06-03"
end = "2025-12-05"

[[trusted.wasi]]
criteria = "safe-to-deploy"
user-id = 6825 # Dan Gohman (sunfishcode)
start = "2019-07-22"
end = "2026-01-21"

[[trusted.wasm-bindgen]]
criteria = "safe-to-deploy"
user-id = 1 # Alex Crichton (alexcrichton)
Expand Down
3 changes: 3 additions & 0 deletions supply-chain/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ audit-as-crates-io = true
[policy.wasmtime-jit-icache-coherence]
audit-as-crates-io = true

[policy.wasmtime-math]
audit-as-crates-io = true

[policy.wasmtime-slab]
audit-as-crates-io = true

Expand Down
27 changes: 27 additions & 0 deletions supply-chain/imports.lock
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ audited_as = "26.0.1"
version = "29.0.0"
audited_as = "27.0.0"

[[unpublished.wasmtime-jit-icache-coherence]]
version = "30.0.0"
audited_as = "28.0.0"

[[unpublished.wasmtime-math]]
version = "30.0.0"
audited_as = "29.0.0"

[[unpublished.wasmtime-slab]]
version = "28.0.0"
audited_as = "26.0.1"
Expand Down Expand Up @@ -1132,6 +1140,13 @@ user-id = 1
user-login = "alexcrichton"
user-name = "Alex Crichton"

[[publisher.wasi]]
version = "0.13.3+wasi-0.2.2"
when = "2024-10-08"
user-id = 1
user-login = "alexcrichton"
user-name = "Alex Crichton"

[[publisher.wasi-common]]
version = "27.0.0"
when = "2024-11-20"
Expand Down Expand Up @@ -1299,6 +1314,12 @@ when = "2024-11-20"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wasmtime-math]]
version = "29.0.0"
when = "2025-01-20"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wasmtime-slab]]
version = "27.0.0"
when = "2024-11-20"
Expand Down Expand Up @@ -1609,6 +1630,12 @@ when = "2024-11-13"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wit-bindgen-rt]]
version = "0.33.0"
when = "2024-09-30"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wit-bindgen-rt]]
version = "0.35.0"
when = "2024-11-13"
Expand Down
12 changes: 12 additions & 0 deletions tests/all/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2059,6 +2059,18 @@ after empty
])?;
Ok(())
}

#[test]
fn cli_multiple_preopens() -> Result<()> {
run_wasmtime(&[
"run",
"--dir=/::/a",
"--dir=/::/b",
"--dir=/::/c",
CLI_MULTIPLE_PREOPENS_COMPONENT,
])?;
Ok(())
}
}

#[test]
Expand Down

0 comments on commit e304726

Please sign in to comment.