WebAssembly / spec

WebAssembly specification, reference interpreter, and test suite.
https://webassembly.github.io/spec/
Other
3.09k stars 438 forks source link

Wrong test cases in memory_init.wast #1713

Closed r1ru closed 7 months ago

r1ru commented 7 months ago

The following two test cases exist in memory_init.wast

unknown-data-segment

unknown-memory

https://github.com/WebAssembly/spec/blob/main/test/core/memory_init.wast#L189-L193 https://github.com/WebAssembly/spec/blob/main/test/core/memory_init.wast#L226-L230

However, what is expected in these tests is not consistent with what is expected in binary.wast below.

datacountsection_required

https://github.com/WebAssembly/spec/blob/main/test/core/binary.wast#L472-L511

These two tests should also fail at the decoding stage because the data count section is not defined. Therefore, these tests should be modified or deleted.

rossberg commented 7 months ago

Hm, I'm confused, can you elaborate what is inconsistent? (Note that the text format has no explicit representation of the data count section, it is implied when there is a non-zero number of data segments.)

r1ru commented 7 months ago

Okay, then this is my mistake. I thoght it is inconsistent because when I input the above memory_init.wast into wast2json, it outputs wasm binaries without the data count section. Probably this is a bug of wast2json. Sorry.

rossberg commented 7 months ago

Well, strictly speaking, the spec requires a data count section iff there is at least one occurrence of a data index in the program, which is the case in the first example. But that also has no data segment, hence it would be invalid either way. In practical terms, it doesn't really matter what a tool does in the case of invalid input, so I'm not sure I would necessarily count it as a bug.