Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.
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

Closed

Description

@RReverser

While implementing bulk memory proposal in my parser, I've noticed regressions in some core spec tests. In particular these two are very representative:

(module binary
"\00asm" "\01\00\00\00"
"\05\03\01" ;; Memory section with 1 entry
"\00\00" ;; no max, minimum 0
"\0b\07\01" ;; Data section with 1 entry
"\80\00" ;; Memory index 0, encoded with 2 bytes
"\41\00\0b\00" ;; (i32.const 0) with contents ""
)
(module binary
"\00asm" "\01\00\00\00"
"\04\04\01" ;; Table section with 1 entry
"\70\00\00" ;; no max, minimum 0, funcref
"\09\07\01" ;; Element section with 1 entry
"\80\00" ;; Table index 0, encoded with 2 bytes
"\41\00\0b\00" ;; (i32.const 0) with no elements
)

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:

image

image

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.

Activity

  1. added a commit that references this issue on Jun 4, 2020
  2. gahaas commented on Jun 4, 2020

    @gahaas
    Contributor

    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.

  3. RReverser commented on Jun 4, 2020

    @RReverser
    MemberAuthor

    @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.

  4. RReverser commented on Jun 4, 2020

    @RReverser
    MemberAuthor

    Just looked up, these are the other 2 tests this is another test incompatible with new layout (aside from 2 above):

    ;; Data segment memory index can have non-minimal length
    (module binary
    "\00asm" "\01\00\00\00"
    "\05\03\01" ;; Memory section with 1 entry
    "\00\00" ;; no max, minimum 0
    "\0b\07\01" ;; Data section with 1 entry
    "\80\00" ;; Memory index 0, encoded with 2 bytes
    "\41\00\0b\00" ;; (i32.const 0) with contents ""
    )

  5. RReverser commented on Jun 22, 2020

    @RReverser
    MemberAuthor

    @binji @gahaas Is this going to be resolved in one way or another before moving to stage 4? Seems dangerous from backward compatibility PoV.

  6. binji commented on Jun 22, 2020

    @binji
    Member

    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.

  7. RReverser commented on Jun 23, 2020

    @RReverser
    MemberAuthor

    it would only happen if someone did it manually

    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.

  8. binji commented on Jun 23, 2020

    @binji
    Member

    Perhaps, though generally tools only do that for LEB128 values that represent a count/size that needs to be fixed-up.

  9. RReverser commented on Jun 24, 2020

    @RReverser
    MemberAuthor

    I assumed that index encoding shares same routines as count/size?

  10. RReverser commented on Jun 24, 2020

    @RReverser
    MemberAuthor

    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.

    But you're right that it would be good to mention and remove tests.

    Let's just do this then (test removal and explicit documentation).

  11. added a commit that references this issue on Oct 12, 2020
  12. rossberg commented on Feb 10, 2021

    @rossberg
    Member

    I believe this was resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions