Skip to content

Commit 60ff869

Browse files
authored
wast: Fix pointer provenance bug reported by MIRI (#1386)
* wast: Fix pointer provenance bug reported by MIRI We need to re-derive the str pointer after moving the original `Box<str>` it was derived from. * wast: Remove all unsafe, use bumpalo for arena This removes the single unsafe block from the `wast` crate. The unsafe block was extending the lifetime of some data by moving into an ad-hoc arena. We replace that usage with `bumpalo`, which is well-tested, vetted, and etc... * Default all crates in the workspace to `deny(unsafe_code)` A couple crates still contain unsafe code: one block in `wasmparser` and all throughout the C API. These have comments explaining their safety. The one unsafe block that used to exist in `wasm-smith` has been removed. It was an optimization to avoid double UTF-8 validation when constructing a `str` from bytes. We simply validate twice now, since that cost should be negligible in the context of the full Wasm test case generation. * cargo fmt
1 parent a6160b3 commit 60ff869

File tree

23 files changed

+70
-15
lines changed

23 files changed

+70
-15
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ repository = "https://github.com/bytecodealliance/wasm-tools"
1212
readme = "README.md"
1313
exclude = ['tests/wabt', 'tests/testsuite', 'tests/snapshots', 'ci']
1414

15+
[lints]
16+
workspace = true
17+
1518
[workspace]
1619
members = [
1720
'crates/c-api',
@@ -21,6 +24,12 @@ members = [
2124
'crates/wit-parser/fuzz',
2225
]
2326

27+
[workspace.lints.rust]
28+
unsafe_code = "deny"
29+
30+
[workspace.lints.clippy]
31+
all = "allow"
32+
2433
[workspace.package]
2534
edition = '2021'
2635

crates/c-api/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ doc = false
1717
test = false
1818
doctest = false
1919

20+
[lints]
21+
workspace = true
22+
2023
[dependencies]
2124
arbitrary = { workspace = true, features = ["derive"] }
2225
wasm-mutate = { workspace = true }

crates/c-api/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
//! files of the `include` directory for this crate.
66
77
#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
8+
// This crate fundamentally is doing a lot of unsafe FFI and stuff like that, so
9+
// it doesn't make sense to allow each individual unsafe block.
10+
#![allow(unsafe_code)]
811

912
use arbitrary::{Error, Unstructured};
1013
use wasm_smith::{Config, Module};

crates/fuzz-stats/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ rand = { workspace = true }
1212
wasm-smith = { workspace = true }
1313
wasmtime = { workspace = true }
1414

15+
[lints]
16+
workspace = true
17+
1518
[lib]
1619
doctest = false
1720
test = false

crates/wasm-compose/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ homepage = "https://github.com/bytecodealliance/wasm-tools/tree/main/crates/wasm
1010
documentation = "https://docs.rs/wasm-compose"
1111
description = "A library for composing WebAssembly components."
1212

13+
[lints]
14+
workspace = true
15+
1316
[dependencies]
1417
wat = { workspace = true }
1518
wasm-encoder = { workspace = true, features = ['wasmparser'] }

crates/wasm-encoder/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ description = """
1212
A low-level WebAssembly encoder.
1313
"""
1414

15+
[lints]
16+
workspace = true
17+
1518
[dependencies]
1619
leb128 = { workspace = true }
1720

crates/wasm-metadata/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ license = "Apache-2.0 WITH LLVM-exception"
66
repository = "https://github.com/bytecodealliance/wasm-tools/tree/main/crates/wasm-metadata"
77
description = "Read and manipulate WebAssembly metadata"
88

9+
[lints]
10+
workspace = true
11+
912
[dependencies]
1013
clap = { workspace = true, optional = true }
1114
anyhow = { workspace = true }

crates/wasm-mutate-stats/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition.workspace = true
55
publish = false
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
anyhow = { workspace = true }
912
arbitrary = { workspace = true }

crates/wasm-mutate/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ license = "Apache-2.0 WITH LLVM-exception"
66
repository = "https://github.com/bytecodealliance/wasm-tools/tree/main/crates/wasm-mutate"
77
description = "A WebAssembly test case mutator"
88

9+
[lints]
10+
workspace = true
11+
912
[dependencies]
1013
clap = { workspace = true, optional = true }
1114
thiserror = "1.0.28"

0 commit comments

Comments
 (0)