You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 3, 2021. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 3, 2021. It is now read-only.
Incompatibility with long LEB128 form from the core spec #153
While implementing bulk memory proposal in my parser, I've noticed regressions in some core spec tests. In particular these two are very representative:
Here, a 0 table index (the only one allowed previously) is encoded in a suboptimal form of 0x80 0x00.
The new layout used by this proposal relies on the table index previously being always zero and encoded as 0x00, and assigns a different meaning to byte at the same position as 0x80 and expects it to be one of the following values:
Such long form is likely not something used by implementations in the wild, but it might be worth double-checking and either supporting such long form too, or at least making an explicit decision about this backward-incompatible binary representation change and removing (?) corresponding tests.
I doubt the long form is used anywhere (it would only happen if someone did it manually), so the backward compatibility risk seems relatively low. But you're right that it would be good to mention and remove tests.
It could in theory also happen if an encoder used a 5-byte-padded LEB128 form to start with (like e.g. LLVM does at initial stage), but then didn't optimise it away in post-processing.
Activity
[test] Fix table index encoding
gahaas commentedon Jun 4, 2020
I saw and fixed this issue already in the reference-type proposal. I guess we should also apply the fix here. I created a PR for that.
RReverser commentedon Jun 4, 2020
@gahaas Note that the test above (for data section) exhibits the same problem, as well as 2 more other tests which previously used long form of zero.
RReverser commentedon Jun 4, 2020
Just looked up,
these are the other 2 teststhis is another test incompatible with new layout (aside from 2 above):bulk-memory-operations/test/core/binary.wast
Lines 118 to 126 in 66d90a7
RReverser commentedon Jun 22, 2020
@binji @gahaas Is this going to be resolved in one way or another before moving to stage 4? Seems dangerous from backward compatibility PoV.
binji commentedon Jun 22, 2020
I doubt the long form is used anywhere (it would only happen if someone did it manually), so the backward compatibility risk seems relatively low. But you're right that it would be good to mention and remove tests.
RReverser commentedon Jun 23, 2020
It could in theory also happen if an encoder used a 5-byte-padded LEB128 form to start with (like e.g. LLVM does at initial stage), but then didn't optimise it away in post-processing.
binji commentedon Jun 23, 2020
Perhaps, though generally tools only do that for LEB128 values that represent a count/size that needs to be fixed-up.
RReverser commentedon Jun 24, 2020
I assumed that index encoding shares same routines as count/size?
binji commentedon Jun 24, 2020
Binaryen has different functions for fixed- and variable-length LEB128: https://github.com/WebAssembly/binaryen/blob/master/src/wasm-binary.h#L73-L104
So does wabt: https://github.com/WebAssembly/wabt/blob/master/src/leb128.cc#L49-L65
Maybe LLVM does it differently?
tlively commentedon Jun 24, 2020
LLVM also can do it both ways: https://github.com/llvm/llvm-project/blob/master/llvm/include/llvm/Support/LEB128.h
It doesn't look like lld uses any padding when emitting the memory index:
RReverser commentedon Jun 24, 2020
Thanks for checking! I guess if both Binaryen and LLVM don't do this, we should be on safe-ish side as that covers most toolchains.
Let's just do this then (test removal and explicit documentation).
[test] Fix table index encoding (#154)
Ignore failures from incompatible proposals
rossberg commentedon Feb 10, 2021
I believe this was resolved.