Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
palkan opened this issue Nov 12, 2024 · 5 comments · May be fixed by palkan/rails-on-wasm-playground#7
Open

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

palkan opened this issue Nov 12, 2024 · 5 comments · May be fixed by palkan/rails-on-wasm-playground#7

Comments

@palkan
Copy link

palkan commented Nov 12, 2024

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
@palkan
Copy link
Author

palkan commented Nov 12, 2024

Good news: the head version works fine.

@kateinoigakukun
Copy link
Member

kateinoigakukun commented Nov 12, 2024

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

@palkan palkan mentioned this issue Nov 14, 2024
2 tasks
@palkan
Copy link
Author

palkan commented Nov 14, 2024

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)

@palkan
Copy link
Author

palkan commented Nov 15, 2024

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

Author: Yuta Saito <[email protected]>
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.

@kateinoigakukun
Copy link
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
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants