Skip to content

MatchData#end returns invalid offset when called within evalAsync #555

Description

@palkan

Stackblitz reproduction: https://stackblitz.com/edit/ruby-wasm-demo-78s71k?file=index.html

MatchData#end returns incorrect match offset when used in async context:

vm.eval(/(т)(е)(с)/.match('тест').end(0)) #=> 3
vm.eval(/(т)(е)(с)/.match('тест').end(1)) #=> 1

vm.evalAsync(/(т)(е)(с)/.match('тест').end(0)) #=> 3291
vm.evalAsync(/(т)(е)(с)/.match('тест').end(1)) #=> 3

Activity

  1. palkan commented on Nov 12, 2024

    @palkan
    Author

    Good news: the head version works fine.

  2. kateinoigakukun commented on Nov 12, 2024

    @kateinoigakukun
    Member

    I'll bisect which nightly head version fixed the issue once I'll get a stable internet connection.

  3. palkan commented on Nov 14, 2024

    @palkan
    Author

    This also crashes Date._parse (within evalAsync):

    app.wasm:0x5739f8 Uncaught RuntimeError: memory access out of bounds
        at enc_strlen (app.wasm:0x5739f7)
        at rb_enc_strlen (app.wasm:0x573574)
        at update_char_offset (app.wasm:0x50cc96)
        at match_begin (app.wasm:0x507547)
        at ractor_safe_call_cfunc_1 (app.wasm:0x67a681)
        at vm_call0_body (app.wasm:0x638879)
        at rb_funcallv_scope (app.wasm:0x637cdb)
        at rb_funcall (app.wasm:0x65269f)
        at subx (app.wasm:0x7ed59)
        at date__parse (app.wasm:0x7bd9b)
    
  4. palkan commented on Nov 15, 2024

    @palkan
    Author

    Okay, I found the fix 😁—ruby/ruby@0d4de0f:

    Author: Yuta Saito <kateinoigakukun@gmail.com>
    Date:   Mon Jan 29 09:49:15 2024 +0000
    
        wasm: align fiber stack pointer to 16 bytes
    
        In WebAssembly C ABI, the linear stack pointer must be always aligned
        to 16 bytes like other archs.
        The misaligned stack pointer causes some weird memory corruption since
        compiler assumes the aligned stack pointer.
    
  5. kateinoigakukun commented on Nov 15, 2024

    @kateinoigakukun
    Member

    I'm sorry about totally forgetting my fix in January... I opened backport PRs for 3.2 and 3.3:

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