MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / test_ptr_out_of_bounds

Function test_ptr_out_of_bounds

tests/all/component_model/strings.rs:206–260  ·  view source on GitHub ↗
(engine: &Engine, src: &str, dst: &str)

Source from the content-addressed store, hash-verified

204}
205
206fn test_ptr_out_of_bounds(engine: &Engine, src: &str, dst: &str) -> Result<()> {
207 let test = |len: u32| -> Result<()> {
208 let component = format!(
209 r#"
210(component
211 (component $c
212 (core module $m
213 (func (export "") (param i32 i32))
214 (func (export "realloc") (param i32 i32 i32 i32) (result i32) i32.const 0)
215 (memory (export "memory") 1)
216 )
217 (core instance $m (instantiate $m))
218 (func (export "a") (param "a" string)
219 (canon lift (core func $m "") (realloc (func $m "realloc")) (memory $m "memory")
220 string-encoding={dst})
221 )
222 )
223
224 (component $c2
225 (import "a" (func $f (param "a" string)))
226 (core module $libc
227 (memory (export "memory") 1)
228 )
229 (core instance $libc (instantiate $libc))
230 (core func $f (canon lower (func $f) string-encoding={src} (memory $libc "memory")))
231 (core module $m
232 (import "" "" (func $f (param i32 i32)))
233
234 (func $start (call $f (i32.const 0x8000_0000) (i32.const {len})))
235 (start $start)
236 )
237 (core instance (instantiate $m (with "" (instance (export "" (func $f))))))
238 )
239
240 (instance $c (instantiate $c))
241 (instance $c2 (instantiate $c2 (with "a" (func $c "a"))))
242)
243"#
244 );
245 let component = Component::new(engine, &component)?;
246 let mut store = Store::new(engine, ());
247 let trap = Linker::new(engine)
248 .instantiate(&mut store, &component)
249 .err()
250 .unwrap()
251 .downcast::<Trap>()?;
252 assert_eq!(trap, Trap::StringOutOfBounds);
253 Ok(())
254 };
255
256 test(0)?;
257 test(1)?;
258
259 Ok(())
260}
261
262// Test that even if the ptr+len calculation overflows then a trap still
263// happens.

Callers 1

ptr_out_of_boundsFunction · 0.85

Calls 6

OkFunction · 0.85
newFunction · 0.50
testFunction · 0.50
unwrapMethod · 0.45
errMethod · 0.45
instantiateMethod · 0.45

Tested by

no test coverage detected