Repository navigation
WASM - elem/data segment validation - #2174
Conversation
|
Hold off a moment to review this, I want to include another fix related to this |
|
Should be okay to review now |
| } | ||
|
|
||
| void | ||
| WebAssemblyModule::ValidateInitExporForOffset(const Wasm::WasmNode& initExpr) const |
There was a problem hiding this comment.
nit: spelling (ValidateInitExprForOffset)
| throw Wasm::WasmCompilationException(_u("Invalid init_expr for element offset")); | ||
| } | ||
| // Should have been checked at compile time, but let's just make sure one more time | ||
| ValidateInitExporForOffset(initExpr); |
There was a problem hiding this comment.
then maybe we should put under #if DBG and assert?
| { | ||
| uint32 index = LEB128(length); // Table id | ||
| if (index != 0) | ||
| if (index != 0 || !(m_module->HasTable() || m_module->HasTableImport())) |
There was a problem hiding this comment.
the spec seemed unclear to me about this. it looked like it might be legal to have no table or table import and have element section, as long as it does nothing (e.g. any segments have length 0)
There was a problem hiding this comment.
I found this bug using the spec invalid tests.
I think it does make sense to be a compile error since the index will be able to refer to different table, we should tell ahead of time that the elements are not using a valid table
There was a problem hiding this comment.
true, but the design says that every module has one default memory/table (not up to one). there is no mention what the state is if there is no explicit table section. so if this is how the spec interpreter behaves then i'm fine deferring to it. just one of those corners that will needed to be worked out in the formal spec
There was a problem hiding this comment.
It feels weird to allow to set data or elements in a memory/table that hasn't been defined.
In our current implementation, we would throw a linking error when treating the data/element segments.
This is only moving the error to compile time effectively changing from WebAssembly.RuntimeError to WebAssembly.CompileError which is more in line with the spec interpreter.
In the end, it really doesn't matter, but early error should be favorable if we have to read the data anyway
| if (initExpr.op != Wasm::wbI32Const && initExpr.op != Wasm::wbGetGlobal) | ||
| try | ||
| { | ||
| ValidateInitExportForOffset(initExpr); |
There was a problem hiding this comment.
I wanted to keep the runtime check even on release builds, so I wrapped it in a try-catch with an assert to help us find errors.
I am not totally convinced by the end result though, what do you think ?
There was a problem hiding this comment.
A bit strange, but seems ok to me.
|
ping |
| if (initExpr.op != Wasm::wbI32Const && initExpr.op != Wasm::wbGetGlobal) | ||
| try | ||
| { | ||
| ValidateInitExportForOffset(initExpr); |
There was a problem hiding this comment.
A bit strange, but seems ok to me.
Validate the init_expr for element and data segments
Update memory.wast from the spec repo
Merge pull request #2174 from Cellule:wasm/elem Check if a table is present when reading an element section Validate the init_expr for element and data segments Disallow internal global in init_expr The issue WebAssembly/spec#367 made me realize we were doing the same thing the spec interpreter was which was not according to the design documents Check the type of init_expr for globals
Merge pull request #2174 from Cellule:wasm/elem Check if a table is present when reading an element section Validate the init_expr for element and data segments Disallow internal global in init_expr The issue WebAssembly/spec#367 made me realize we were doing the same thing the spec interpreter was which was not according to the design documents Check the type of init_expr for globals
Check if a table is present when reading an element section
Validate the init_expr for element and data segments
Disallow internal global in init_expr
The issue WebAssembly/spec#367 made me realize we were doing the same thing the spec interpreter was which was not according to the design documents
Check the type of init_expr for globals
This change is