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

SourceMapProxy::lookup_char_pos causes out of bounds memory access #7238

Closed
kwonoj opened this issue Apr 10, 2023 · 7 comments
Closed

SourceMapProxy::lookup_char_pos causes out of bounds memory access #7238

kwonoj opened this issue Apr 10, 2023 · 7 comments
Assignees
Milestone

Comments

@kwonoj
Copy link
Member

kwonoj commented Apr 10, 2023

Describe the bug

Caused by:
    0: failed to invoke `/home/git_repo/swc-coverage-instrument/target/wasm32-wasi/debug/swc_plugin_coverage.wasm` as js transform plugin at /home/git_repo/swc-coverage-instrument/target/wasm32-wasi/debug/swc_plugin_coverage.wasm
    1: RuntimeError: out of bounds memory access
           at rkyv::impls::core::primitive::_::<impl rkyv::Deserialize<u32,D> for u32>::deserialize::hf987dcd4d5a23f0f (<module>[17174]:0x5db044)
           at swc_common::syntax_pos::_::<impl rkyv::Deserialize<swc_common::syntax_pos::BytePos,__D> for <swc_common::syntax_pos::BytePos as rkyv::Archive>::Archived>::deserialize::h5163a6ad2e68099f (<module>[15351]:0x54ac2b)
           at rkyv::impls::core::<impl rkyv::DeserializeUnsized<[U],D> for [T]>::deserialize_unsized::h76e0cc48824035e5 (<module>[15382]:0x54edcc)
           at rkyv::impls::alloc::vec::<impl rkyv::Deserialize<alloc::vec::Vec<T>,D> for rkyv::vec::ArchivedVec<<T as rkyv::Archive>::Archived>>::deserialize::h0fa332b260d140d0 (<module>[15121]:0x5378db)
           at swc_common::syntax_pos::_::<impl rkyv::Deserialize<swc_common::syntax_pos::SourceFile,__D> for <swc_common::syntax_pos::SourceFile as rkyv::Archive>::Archived>::deserialize::hec4b05966557a119 (<module>[15354]:0x54c143)
           at rkyv::impls::core::<impl rkyv::DeserializeUnsized<T,D> for <T as rkyv::Archive>::Archived>::deserialize_unsized::h2d776c7271413762 (<module>[15376]:0x54e631)
           at rkyv::de::SharedDeserializeRegistry::deserialize_shared::h300466f196606cc5 (<module>[15505]:0x55ef10)
           at rkyv::impls::alloc::rc::<impl rkyv::Deserialize<alloc::sync::Arc<T>,D> for rkyv::rc::ArchivedRc<<T as rkyv::ArchiveUnsized>::Archived,rkyv::impls::alloc::rc::ArcFlavor>>::deserialize::hf1e0d3210d8c554a (<module>[15266]:0x53e959)
           at rkyv::impls::core::option::<impl rkyv::Deserialize<core::option::Option<T>,D> for rkyv::option::ArchivedOption<<T as rkyv::Archive>::Archived>>::deserialize::h80d9a1718ba44314 (<module>[15265]:0x53e806)
           at swc_common::syntax_pos::_::<impl rkyv::Deserialize<swc_common::syntax_pos::PartialLoc,__D> for <swc_common::syntax_pos::PartialLoc as rkyv::Archive>::Archived>::deserialize::h9301913a9cc51a47 (<module>[15353]:0x54b61a)
           at rkyv::util::from_bytes_unchecked::had57a043483f3d49 (<module>[15118]:0x537246)
           at swc_common::plugin::serialized::deserialize_from_ptr_into_fallible::h8a098d42fad0d1a3 (<module>[15415]:0x5578d6)
           at swc_plugin_proxy::memory_interop::read_returned_result_from_host::read_returned_result_from_host_fallible::h44c6572f8961a0f5 (<module>[15290]:0x546e26)
           at <swc_plugin_proxy::source_map::plugin_source_map_proxy::PluginSourceMapProxy as swc_common::errors::SourceMapper>::lookup_char_pos::h5c8986d68be38919 (<module>[15458]:0x559fa4)
           at swc_coverage_instrument::utils::lookup_range::get_range_from_span::h8ed700f54031791c (<module>[8352]:0x2c5242)
           at swc_coverage_instrument::visitors::coverage_visitor::CoverageVisitor<C,S>::create_stmt_increase_counter_expr::h5c67ab25644db914 (<module>[9571]:0x371f27)
           at swc_coverage_instrument::visitors::coverage_visitor::CoverageVisitor<C,S>::mark_prepend_stmt_counter::he63a39e2437af405 (<module>[9305]:0x33efa6)
           at <swc_coverage_instrument::visitors::coverage_visitor::CoverageVisitor<C,S> as swc_ecma_visit::VisitMut>::visit_mut_expr_stmt::hb731676e9217ffc2 (<module>[9320]:0x34b301)
           at swc_ecma_visit::visit_mut_stmt::hb954d5e69df8c163 (<module>[1657]:0xd0389)
           at swc_ecma_visit::VisitMut::visit_mut_stmt::hbde661e6e3a05786 (<module>[9402]:0x36d409)
           at swc_ecma_visit::visit_mut_module_item::hd35b66b661a84631 (<module>[2346]:0xe93b1)
           at <swc_ecma_ast::module::ModuleItem as swc_ecma_visit::VisitMutWith<V>>::visit_mut_children_with::hc28859ead0708ddc (<module>[8350]:0x2c5142)
           at <swc_coverage_instrument::visitors::coverage_visitor::CoverageVisitor<C,S> as swc_ecma_visit::VisitMut>::visit_mut_module_items::h2a3ad5c3e035b5ef (<module>[9367]:0x36570a)
           at swc_ecma_visit::visit_mut_module::h63a35a742db5514f (<module>[1799]:0xd581e)
           at swc_ecma_visit::VisitMut::visit_mut_module::hd66a286600ffdc14 (<module>[9411]:0x36d6b5)
           at swc_ecma_visit::visit_mut_program::h6232fc15a0263211 (<module>[1902]:0xd92da)
           at <swc_ecma_ast::module::Program as swc_ecma_visit::VisitMutWith<V>>::visit_mut_children_with::h5efa94f711ebc180 (<module>[8349]:0x2c50f6)
           at <swc_coverage_instrument::visitors::coverage_visitor::CoverageVisitor<C,S> as swc_ecma_visit::VisitMut>::visit_mut_program::h3a1de69664758423 (<module>[9307]:0x341ada)
           at <swc_ecma_ast::module::Program as swc_ecma_visit::VisitMutWith<V>>::visit_mut_with::hecc44617e977a2da (<module>[8348]:0x2c50aa)
           at <swc_ecma_visit::Folder<V> as swc_ecma_visit::Fold>::fold_program::h58c3af9f8cb6d60b (<module>[3176]:0x105da3)
           at <swc_ecma_ast::module::Program as swc_ecma_visit::FoldWith<V>>::fold_with::ha1f23ad846ccf783 (<module>[8347]:0x2c505e)
           at swc_plugin_coverage::process::hcd587a0687530c45 (<module>[6394]:0x2776d5)
           at __transform_plugin_process_impl (<module>[6399]:0x2784d0)
           at __transform_plugin_process_impl.command_export (<module>[27584]:0x96462b)
    2: heap_get_oob', /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/swc-0.260.1/src/plugin.rs:228:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Error: failed to handle: failed to invoke plugin: failed to invoke plugin on 'Some("anon")'

Caused by:
    0: failed to invoke `/home/git_repo/swc-coverage-instrument/target/wasm32-wasi/debug/swc_plugin_coverage.wasm` as js transform plugin at /home/git_repo/swc-coverage-instrument/target/wasm32-wasi/debug/swc_plugin_coverage.wasm
    1: RuntimeError: out of bounds memory access
           at rkyv::impls::core::primitive::_::<impl rkyv::Deserialize<u32,D> for u32>::deserialize::hf987dcd4d5a23f0f (<module>[17174]:0x5db044)
           at swc_common::syntax_pos::_::<impl rkyv::Deserialize<swc_common::syntax_pos::BytePos,__D> for <swc_common::syntax_pos::BytePos as rkyv::Archive>::Archived>::deserialize::h5163a6ad2e68099f (<module>[15351]:0x54ac2b)
           at rkyv::impls::core::<impl rkyv::DeserializeUnsized<[U],D> for [T]>::deserialize_unsized::h76e0cc48824035e5 (<module>[15382]:0x54edcc)
           at rkyv::impls::alloc::vec::<impl rkyv::Deserialize<alloc::vec::Vec<T>,D> for rkyv::vec::ArchivedVec<<T as rkyv::Archive>::Archived>>::deserialize::h0fa332b260d140d0 (<module>[15121]:0x5378db)
           at swc_common::syntax_pos::_::<impl rkyv::Deserialize<swc_common::syntax_pos::SourceFile,__D> for <swc_common::syntax_pos::SourceFile as rkyv::Archive>::Archived>::deserialize::hec4b05966557a119 (<module>[15354]:0x54c143)
           at rkyv::impls::core::<impl rkyv::DeserializeUnsized<T,D> for <T as rkyv::Archive>::Archived>::deserialize_unsized::h2d776c7271413762 (<module>[15376]:0x54e631)
           at rkyv::de::SharedDeserializeRegistry::deserialize_shared::h300466f196606cc5 (<module>[15505]:0x55ef10)
           at rkyv::impls::alloc::rc::<impl rkyv::Deserialize<alloc::sync::Arc<T>,D> for rkyv::rc::ArchivedRc<<T as rkyv::ArchiveUnsized>::Archived,rkyv::impls::alloc::rc::ArcFlavor>>::deserialize::hf1e0d3210d8c554a (<module>[15266]:0x53e959)
           at rkyv::impls::core::option::<impl rkyv::Deserialize<core::option::Option<T>,D> for rkyv::option::ArchivedOption<<T as rkyv::Archive>::Archived>>::deserialize::h80d9a1718ba44314 (<module>[15265]:0x53e806)
           at swc_common::syntax_pos::_::<impl rkyv::Deserialize<swc_common::syntax_pos::PartialLoc,__D> for <swc_common::syntax_pos::PartialLoc as rkyv::Archive>::Archived>::deserialize::h9301913a9cc51a47 (<module>[15353]:0x54b61a)
           at rkyv::util::from_bytes_unchecked::had57a043483f3d49 (<module>[15118]:0x537246)
           at swc_common::plugin::serialized::deserialize_from_ptr_into_fallible::h8a098d42fad0d1a3 (<module>[15415]:0x5578d6)
           at swc_plugin_proxy::memory_interop::read_returned_result_from_host::read_returned_result_from_host_fallible::h44c6572f8961a0f5 (<module>[15290]:0x546e26)
           at <swc_plugin_proxy::source_map::plugin_source_map_proxy::PluginSourceMapProxy as swc_common::errors::SourceMapper>::lookup_char_pos::h5c8986d68be38919 (<module>[15458]:0x559fa4)
           at swc_coverage_instrument::utils::lookup_range::get_range_from_span::h8ed700f54031791c (<module>[8352]:0x2c5242)
           at swc_coverage_instrument::visitors::coverage_visitor::CoverageVisitor<C,S>::create_stmt_increase_counter_expr::h5c67ab25644db914 (<module>[9571]:0x371f27)
           at swc_coverage_instrument::visitors::coverage_visitor::CoverageVisitor<C,S>::mark_prepend_stmt_counter::he63a39e2437af405 (<module>[9305]:0x33efa6)
           at <swc_coverage_instrument::visitors::coverage_visitor::CoverageVisitor<C,S> as swc_ecma_visit::VisitMut>::visit_mut_expr_stmt::hb731676e9217ffc2 (<module>[9320]:0x34b301)
           at swc_ecma_visit::visit_mut_stmt::hb954d5e69df8c163 (<module>[1657]:0xd0389)
           at swc_ecma_visit::VisitMut::visit_mut_stmt::hbde661e6e3a05786 (<module>[9402]:0x36d409)
           at swc_ecma_visit::visit_mut_module_item::hd35b66b661a84631 (<module>[2346]:0xe93b1)
           at <swc_ecma_ast::module::ModuleItem as swc_ecma_visit::VisitMutWith<V>>::visit_mut_children_with::hc28859ead0708ddc (<module>[8350]:0x2c5142)
           at <swc_coverage_instrument::visitors::coverage_visitor::CoverageVisitor<C,S> as swc_ecma_visit::VisitMut>::visit_mut_module_items::h2a3ad5c3e035b5ef (<module>[9367]:0x36570a)
           at swc_ecma_visit::visit_mut_module::h63a35a742db5514f (<module>[1799]:0xd581e)
           at swc_ecma_visit::VisitMut::visit_mut_module::hd66a286600ffdc14 (<module>[9411]:0x36d6b5)
           at swc_ecma_visit::visit_mut_program::h6232fc15a0263211 (<module>[1902]:0xd92da)
           at <swc_ecma_ast::module::Program as swc_ecma_visit::VisitMutWith<V>>::visit_mut_children_with::h5efa94f711ebc180 (<module>[8349]:0x2c50f6)
           at <swc_coverage_instrument::visitors::coverage_visitor::CoverageVisitor<C,S> as swc_ecma_visit::VisitMut>::visit_mut_program::h3a1de69664758423 (<module>[9307]:0x341ada)
           at <swc_ecma_ast::module::Program as swc_ecma_visit::VisitMutWith<V>>::visit_mut_with::hecc44617e977a2da (<module>[8348]:0x2c50aa)
           at <swc_ecma_visit::Folder<V> as swc_ecma_visit::Fold>::fold_program::h58c3af9f8cb6d60b (<module>[3176]:0x105da3)
           at <swc_ecma_ast::module::Program as swc_ecma_visit::FoldWith<V>>::fold_with::ha1f23ad846ccf783 (<module>[8347]:0x2c505e)
           at swc_plugin_coverage::process::hcd587a0687530c45 (<module>[6394]:0x2776d5)
           at __transform_plugin_process_impl (<module>[6399]:0x2784d0)
           at __transform_plugin_process_impl.command_export (<module>[27584]:0x96462b)
    2: heap_get_oob
    at Compiler.transformSync (/home/git_repo/swc-coverage-instrument/node_modules/@swc/core/index.js:241:29)
    at transformSync (/home/git_repo/swc-coverage-instrument/node_modules/@swc/core/index.js:348:21)
    at instrumentSync (/home/git_repo/swc-coverage-instrument/spec/util/verifier.ts:74:23)
    at Object.<anonymous> (/home/git_repo/swc-coverage-instrument/spec/fixture.spec.ts:11:15)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Module._compile (/home/git_repo/swc-coverage-instrument/node_modules/pirates/lib/index.js:136:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.newLoader [as .ts] (/home/git_repo/swc-coverage-instrument/node_modules/pirates/lib/index.js:141:7)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.exports.requireOrImport (/home/git_repo/swc-coverage-instrument/node_modules/mocha/lib/nodejs/esm-utils.js:49:16)
    at Object.exports.loadFilesAsync (/home/git_repo/swc-coverage-instrument/node_modules/mocha/lib/nodejs/esm-utils.js:91:20)
    at singleRun (/home/git_repo/swc-coverage-instrument/node_modules/mocha/lib/cli/run-helpers.js:125:3)
    at Object.exports.handler (/home/git_repo/swc-coverage-instrument/node_modules/mocha/lib/cli/run.js:370:5)

Input code

No response

Config

No response

Playground link

No response

Expected behavior

should not oob

Actual behavior

No response

Version

latest

Additional context

No response

@kwonoj
Copy link
Member Author

kwonoj commented Apr 10, 2023

Note I could observe this only on aarch64 machines so far (m1 / aarch64 linux) but x86_64 passes. Possibly another case of #5406.

@kdy1 kdy1 added this to the Planned milestone Apr 10, 2023
@kwonoj
Copy link
Member Author

kwonoj commented Apr 11, 2023

Actually this seems like #6852.

@kwonoj
Copy link
Member Author

kwonoj commented Apr 12, 2023

wasmerio/wasmer#3764

@rinarakaki

This comment was marked as off-topic.

@kwonoj
Copy link
Member Author

kwonoj commented Apr 15, 2023

next.js issue is not relevant here since next.js is not using the corresponding swc_core yet.

This was referenced Apr 17, 2023
kdy1 pushed a commit that referenced this issue Apr 19, 2023
kdy1 pushed a commit that referenced this issue Apr 24, 2023
**Description:**

Attempt to workaround #7238.

Originally I thought this is related with oom or memory layout, then realized actual deserialization error occurs in weird position - it tries to deserialize BytePos (which is obvious type) and it fails. It made me think maybe a property next to the struct layout have some unexpected behavior, notably Arc<String>.

PR applies same workaround as Atom does, and it seems to at least pass swc-coverage-instrument's usecases. May need bit more verification with other plugins to see if we can call this out as reliable workaround.
kdy1 pushed a commit that referenced this issue May 6, 2023
**Description:**

Second attempt to enable bytecheck. This PR does not have versioned struct yet, just enabling bytecheck wherever possible. Also, it is for the ast only yet, so transform metadata and others might need this later.

PR seems to be passing all the ci, but as we've experienced before, there might be some unexpected outcomes with the release. Maybe better to hold this until clear #7238, then land as a separate release.
@kwonoj
Copy link
Member Author

kwonoj commented May 7, 2023

Tentatively closing as we applied workaround.

@kwonoj kwonoj closed this as completed May 7, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.57 May 9, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Jun 8, 2023

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 Jun 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

4 participants