parity-wasm icon indicating copy to clipboard operation
parity-wasm copied to clipboard

Builder silently drops custom sections

Open osa1 opened this issue 5 years ago • 1 comments

Repro:

use parity_wasm::elements::Section;

fn main() {
    let path = std::env::args().nth(1).unwrap();
    let module = parity_wasm::deserialize_file(&path).unwrap();
    let module_old = module.clone().into_sections();
    let mbuilder = parity_wasm::builder::from_module(module);
    let module_new = mbuilder.build().into_sections();
    println!(
        "old sections: {:?}",
        module_old.iter().map(section_name).collect::<Vec<_>>()
    );
    println!(
        "new sections: {:?}",
        module_new.iter().map(section_name).collect::<Vec<_>>()
    );
}

fn section_name(section: &Section) -> &'static str {
    match section {
        Section::Unparsed { .. } => "unparsed",
        Section::Custom(_) => "custom",
        Section::Type(_) => "type",
        Section::Import(_) => "import",
        Section::Function(_) => "function",
        Section::Table(_) => "table",
        Section::Memory(_) => "memory",
        Section::Global(_) => "global",
        Section::Export(_) => "export",
        Section::Start(_) => "start",
        Section::Element(_) => "element",
        Section::DataCount(_) => "datacount",
        Section::Code(_) => "code",
        Section::Data(_) => "data",
        Section::Name(_) => "name",
        Section::Reloc(_) => "reloc",
    }
}

If I pass this a .wasm file with custom sections I see an output like:

old sections: ["type", "import", "function", "table", "memory", "global", "export", "element", "code", "data", "custom", "custom", "custom", "custom", "custom", "custom", "custom", "custom", "custom", "custom"]
new sections: ["type", "import", "function", "table", "memory", "global", "export", "element", "code", "data"]

So builder drops the custom sections. This is quite unexpected to me, and it's also not documented. Other sections are preserved, I'm not sure why custom sections are dropped.

osa1 avatar Dec 14 '20 12:12 osa1

Hello @osa1, thanks for reporting this issue. Could you please check if you still run into this issue with your wasm?

I ran a test and the custom section was preserved. I think this might have been fixed in #300

chevdor avatar May 12 '21 08:05 chevdor