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

RuntimeError: out of bounds memory access #6464

Closed
mansona opened this issue Nov 17, 2022 · 3 comments
Closed

RuntimeError: out of bounds memory access #6464

mansona opened this issue Nov 17, 2022 · 3 comments
Assignees
Labels

Comments

@mansona
Copy link

mansona commented Nov 17, 2022

Describe the bug

Hey folks 👋 I'm still trying to get to grips with the debugging strategy of this setup, I'm only new to Rust and I've never run anything in WASM on Node before so forgive me if I answer "I don't know" a few too many times if asked any clarifying questions 😂

Essentially I'm trying to debug the format-js swc plugin on our main codebase. I've gotten around a few build issues but now that I've updated everything I have gotten a new error that seems to come from the swc_core AST functions 🤔

here is the full output of the command RUST_BACKTRACE=full RUST_LOG=trace SWC_DEBUG=1 node -r @swc-node/register ./app.ts

Panic: PanicInfo { payload: Any { .. }, message: Some(failed to invoke plugin: failed to invoke plugin on 'Some("/Users/mansona/git/company-name/product-name-api/app.ts")'

Caused by:
    0: failed to invoke `SWC-plugin-formatjs` as js transform plugin at node_modules/SWC-plugin-formatjs/target/wasm32-wasi/release/swc_plugin_formatjs.wasm
    1: RuntimeError: out of bounds memory access
           at swc_ecma_ast::stmt::_::<impl rkyv::Deserialize<swc_ecma_ast::stmt::Stmt,__D> for <swc_ecma_ast::stmt::Stmt as rkyv::Archive>::Archived>::deserialize::h52c724a2b89d6e4d (<module>[4161]:0x1b2c25)
           at rkyv::impls::core::<impl rkyv::DeserializeUnsized<[U],D> for [T]>::deserialize_unsized::hf633033863a7eb6c (<module>[4239]:0x1cc7bf)
           at rkyv::impls::alloc::vec::<impl rkyv::Deserialize<alloc::vec::Vec<T>,D> for rkyv::vec::ArchivedVec<<T as rkyv::Archive>::Archived>>::deserialize::ha1a3efbb9c0959cd (<module>[4117]:0x1b01a3)
           at swc_ecma_ast::stmt::_::<impl rkyv::Deserialize<swc_ecma_ast::stmt::BlockStmt,__D> for <swc_ecma_ast::stmt::BlockStmt as rkyv::Archive>::Archived>::deserialize::he59822f8ae63c300 (<module>[4162]:0x1b6800)
           at swc_ecma_ast::stmt::_::<impl rkyv::Deserialize<swc_ecma_ast::stmt::Stmt,__D> for <swc_ecma_ast::stmt::Stmt as rkyv::Archive>::Archived>::deserialize::h52c724a2b89d6e4d (<module>[4161]:0x1b2cba)
           at swc_ecma_ast::module::_::<impl rkyv::Deserialize<swc_ecma_ast::module::ModuleItem,__D> for <swc_ecma_ast::module::ModuleItem as rkyv::Archive>::Archived>::deserialize::h7bf6e1fe15456600 (<module>[1785]:0x1085ba)
           at rkyv::impls::core::<impl rkyv::DeserializeUnsized<[U],D> for [T]>::deserialize_unsized::h2657b5f3d57fca0e (<module>[1799]:0x10cae0)
           at rkyv::impls::alloc::vec::<impl rkyv::Deserialize<alloc::vec::Vec<T>,D> for rkyv::vec::ArchivedVec<<T as rkyv::Archive>::Archived>>::deserialize::hb9a53d170909d456 (<module>[4121]:0x1b0b93)
           at swc_ecma_ast::module::_::<impl rkyv::Deserialize<swc_ecma_ast::module::Module,__D> for <swc_ecma_ast::module::Module as rkyv::Archive>::Archived>::deserialize::hc434578dffe91338 (<module>[1782]:0x10751a)
           at swc_ecma_ast::module::_::<impl rkyv::Deserialize<swc_ecma_ast::module::Program,__D> for <swc_ecma_ast::module::Program as rkyv::Archive>::Archived>::deserialize::h64b884a6a15f7120 (<module>[1784]:0x107db4)
           at swc_common::plugin::serialized::PluginSerializedBytes::deserialize::hccf37232c8eda7d2 (<module>[5545]:0x23c4e0)
           at swc_common::plugin::serialized::deserialize_from_ptr::hc619d9c789ebc4fa (<module>[5544]:0x23b841)
           at __transform_plugin_process_impl (<module>[2592]:0x13f54a)
           at __transform_plugin_process_impl.command_export (<module>[21517]:0x8056a5)
    2: heap_get_oob), location: Location { file: "/Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/swc-0.226.32/src/plugin.rs", line: 228, col: 14 }, can_unwind: true }
Backtrace:    0: <unknown>
   1: <unknown>
   2: _napi_register_module_v1
   3: _napi_register_module_v1
   4: _napi_register_module_v1
   5: _napi_register_module_v1
   6: _wasmer_vm_raise_trap
   7: _wasmer_vm_raise_trap
   8: _napi_register_module_v1
   9: _napi_register_module_v1
  10: _napi_register_module_v1
  11: _napi_register_module_v1
  12: <unknown>
  13: <unknown>
  14: __ZN6v8impl12_GLOBAL__N_123FunctionCallbackWrapper6InvokeERKN2v820FunctionCallbackInfoINS2_5ValueEEE
  15: __ZN2v88internal25FunctionCallbackArguments4CallENS0_15CallHandlerInfoE
  16: __ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS0_6HandleINS0_10HeapObjectEEESA_NS8_INS0_20FunctionTemplateInfoEEENS8_IS4_EENS0_16BuiltinArgumentsE
  17: __ZN2v88internal21Builtin_HandleApiCallEiPmPNS0_7IsolateE

/Users/mansona/git/company-name/swc-node/node_modules/.pnpm/@swc+core@1.3.2/node_modules/@swc/core/index.js:241
            return bindings.transformSync(isModule ? JSON.stringify(src) : src, isModule, toBuffer(newOptions));
                            ^

Error: failed to handle: failed to invoke plugin: failed to invoke plugin on 'Some("/Users/mansona/git/company-name/product-name-api/app.ts")'

Caused by:
    0: failed to invoke `SWC-plugin-formatjs` as js transform plugin at node_modules/SWC-plugin-formatjs/target/wasm32-wasi/release/swc_plugin_formatjs.wasm
    1: RuntimeError: out of bounds memory access
           at swc_ecma_ast::stmt::_::<impl rkyv::Deserialize<swc_ecma_ast::stmt::Stmt,__D> for <swc_ecma_ast::stmt::Stmt as rkyv::Archive>::Archived>::deserialize::h52c724a2b89d6e4d (<module>[4161]:0x1b2c25)
           at rkyv::impls::core::<impl rkyv::DeserializeUnsized<[U],D> for [T]>::deserialize_unsized::hf633033863a7eb6c (<module>[4239]:0x1cc7bf)
           at rkyv::impls::alloc::vec::<impl rkyv::Deserialize<alloc::vec::Vec<T>,D> for rkyv::vec::ArchivedVec<<T as rkyv::Archive>::Archived>>::deserialize::ha1a3efbb9c0959cd (<module>[4117]:0x1b01a3)
           at swc_ecma_ast::stmt::_::<impl rkyv::Deserialize<swc_ecma_ast::stmt::BlockStmt,__D> for <swc_ecma_ast::stmt::BlockStmt as rkyv::Archive>::Archived>::deserialize::he59822f8ae63c300 (<module>[4162]:0x1b6800)
           at swc_ecma_ast::stmt::_::<impl rkyv::Deserialize<swc_ecma_ast::stmt::Stmt,__D> for <swc_ecma_ast::stmt::Stmt as rkyv::Archive>::Archived>::deserialize::h52c724a2b89d6e4d (<module>[4161]:0x1b2cba)
           at swc_ecma_ast::module::_::<impl rkyv::Deserialize<swc_ecma_ast::module::ModuleItem,__D> for <swc_ecma_ast::module::ModuleItem as rkyv::Archive>::Archived>::deserialize::h7bf6e1fe15456600 (<module>[1785]:0x1085ba)
           at rkyv::impls::core::<impl rkyv::DeserializeUnsized<[U],D> for [T]>::deserialize_unsized::h2657b5f3d57fca0e (<module>[1799]:0x10cae0)
           at rkyv::impls::alloc::vec::<impl rkyv::Deserialize<alloc::vec::Vec<T>,D> for rkyv::vec::ArchivedVec<<T as rkyv::Archive>::Archived>>::deserialize::hb9a53d170909d456 (<module>[4121]:0x1b0b93)
           at swc_ecma_ast::module::_::<impl rkyv::Deserialize<swc_ecma_ast::module::Module,__D> for <swc_ecma_ast::module::Module as rkyv::Archive>::Archived>::deserialize::hc434578dffe91338 (<module>[1782]:0x10751a)
           at swc_ecma_ast::module::_::<impl rkyv::Deserialize<swc_ecma_ast::module::Program,__D> for <swc_ecma_ast::module::Program as rkyv::Archive>::Archived>::deserialize::h64b884a6a15f7120 (<module>[1784]:0x107db4)
           at swc_common::plugin::serialized::PluginSerializedBytes::deserialize::hccf37232c8eda7d2 (<module>[5545]:0x23c4e0)
           at swc_common::plugin::serialized::deserialize_from_ptr::hc619d9c789ebc4fa (<module>[5544]:0x23b841)
           at __transform_plugin_process_impl (<module>[2592]:0x13f54a)
           at __transform_plugin_process_impl.command_export (<module>[21517]:0x8056a5)
    2: heap_get_oob
    at Compiler.transformSync (/Users/mansona/git/company-name/swc-node/node_modules/.pnpm/@swc+core@1.3.2/node_modules/@swc/core/index.js:241:29)
    at transformSync (/Users/mansona/git/company-name/swc-node/node_modules/.pnpm/@swc+core@1.3.2/node_modules/@swc/core/index.js:348:21)
    at transformSync (/Users/mansona/git/company-name/swc-node/packages/core/index.ts:69:26)
    at compile (/Users/mansona/git/company-name/swc-node/packages/register/register.ts:50:40)
    at exts (/Users/mansona/git/company-name/swc-node/packages/register/register.ts:61:38)
    at Module._compile (/Users/mansona/git/company-name/swc-node/node_modules/.pnpm/pirates@4.0.5/node_modules/pirates/lib/index.js:130:29)
    at Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Object.newLoader [as .ts] (/Users/mansona/git/company-name/swc-node/node_modules/.pnpm/pirates@4.0.5/node_modules/pirates/lib/index.js:141:7)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12) {
  code: 'GenericFailure'
}

Obviously I'm dealing with a plugin here so it may make more sense to open this issue there, but considering the "shape" of the stacktrace I thought it might make more sense to open the issue here 👍

Input code

I haven't identified the part of the code that is causing the problem yet. Any debugging tips or techniques that you recommend I am all ears

Config

No response

Playground link

No response

Expected behavior

I thought it was very difficult to get out-of-bounds errors in Rust 😂

Actual behavior

No response

Version

I'm not 100% sure what this is asking

Additional context

No response

@mansona mansona added the C-bug label Nov 17, 2022
@mansona
Copy link
Author

mansona commented Nov 17, 2022

so i continued to push on this and it seems like updating @swc/core in my fork of @swc/register might have fixed this 🤔

Essentially I've been tracking this down for the last day or so and my conclusion is that every part of swc needs to be on the exact same version to get this to work. All the node parts, all the plugins need to be built with the same version etc.

I guess this issue is really about error messages and making things more accessible for people like me that only have a vague understanding of what might be wrong. I wonder if there is any methods that we can use to verify the versions of things and fail with a nice error message "this is not compatible with the version you are running, update X and try again" or something like that

thoughts?

@kwonoj
Copy link
Member

kwonoj commented Nov 17, 2022

There is #5060 to ensure & detect things more gradual manner.

As you already figured out and as I commented in original PR, currently this is likely coming from host - plugin version mismatch. I'll close this for now and track meta issue via 5060.

@kwonoj kwonoj closed this as completed Nov 17, 2022
@swc-bot
Copy link
Collaborator

swc-bot commented Dec 18, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Dec 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants