mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 12:16:39 +00:00
Merge pull request #8964 from dotCooCoo/feat/plugin-manifest-section
Plug-ins: read the manifest from a custom section before running any code
This commit is contained in:
@@ -2017,6 +2017,23 @@ fn a_heavy_filter_installs_once_the_user_agrees() {
|
||||
assert!(install(&mut s, DESATURATE).get("budget").is_none());
|
||||
}
|
||||
|
||||
/// A module that carries its manifest in a `vc_manifest` custom section is inspected and installed
|
||||
/// without any of its code running: its start function traps and its `vc_manifest` export loops.
|
||||
#[test]
|
||||
fn a_plugin_with_a_manifest_section_installs_without_running() {
|
||||
let mut s = session();
|
||||
let id = "test.engine.section";
|
||||
let manifest = format!(r#"{{"id":"{id}","name":"Test {id}","version":"1","kind":"filter","abi":1}}"#);
|
||||
let extra = r#"(func (export "vc_manifest") (result i64) (loop $l (br $l)) (i64.const 0)) (func $trap unreachable) (start $trap)"#;
|
||||
let data = vectorcraft_format::base64_encode(&wat::parse_str(tpl::sectioned(&manifest, tpl::ECHO, extra, 1)).unwrap());
|
||||
let inspected = run(&mut s, "plugin.inspect", json!({"dataBase64": data}));
|
||||
assert_eq!(inspected["id"], id);
|
||||
assert!(vectorcraft_plugins::registry::get(id).is_none(), "inspecting installs nothing");
|
||||
assert_eq!(run(&mut s, "plugin.install", json!({"dataBase64": data}))["id"], id);
|
||||
assert!(vectorcraft_plugins::registry::get(id).is_some());
|
||||
run(&mut s, "plugin.remove", json!({"id": id}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_install_flags_are_refused() {
|
||||
let mut s = session();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Untrusted plug-ins never crash the app: mutated and garbage modules handed to `plugin.install`,
|
||||
//! and plug-ins returning hostile output (random JSON in the object model's shape: huge or
|
||||
//! malformed coordinates, unknown ids, broken paints and gradients, junk of every type) as object
|
||||
//! Untrusted plug-ins never crash the app: mutated and garbage modules, and modules whose
|
||||
//! `vc_manifest` custom section holds garbage, handed to `plugin.install`, and plug-ins returning
|
||||
//! hostile output (random JSON in the object model's shape: huge or malformed coordinates, unknown ids, broken paints and gradients, junk of every type) as object
|
||||
//! filters (`plugin.run`) or live effects (`effect.apply`), and plug-ins running bulk memory
|
||||
//! instructions (`memory.fill`, `memory.copy`, `memory.init`, `data.drop`) on ranges in, at and past
|
||||
//! the ends of memory and the data segment, under small and default budgets. Each run must end as
|
||||
@@ -620,7 +620,11 @@ proptest! {
|
||||
}
|
||||
let mut s = rich_session();
|
||||
s.execute("select.all", &json!({})).unwrap();
|
||||
for module in [bytes, [b"\0asm\x01\0\0\0".as_slice(), &garbage].concat(), garbage.clone()] {
|
||||
// A module whose `vc_manifest` custom section holds the garbage.
|
||||
let section = tpl::custom_section(vectorcraft_plugins::manifest::MANIFEST_SECTION, &garbage);
|
||||
let sectioned = tpl::with_field(&tpl::module(&tpl::manifest("fuzz.section", "filter", "{}"), tpl::ECHO, "", 1), §ion).unwrap();
|
||||
let sectioned = wat::parse_str(sectioned).unwrap();
|
||||
for module in [bytes, [b"\0asm\x01\0\0\0".as_slice(), &garbage].concat(), garbage.clone(), sectioned] {
|
||||
let r = catch_quiet(|| {
|
||||
if let Ok(info) = install(&mut s, &module) {
|
||||
let _ = s.execute("plugin.run", &json!({"id": info["id"]}));
|
||||
|
||||
Reference in New Issue
Block a user