-
-
Notifications
You must be signed in to change notification settings - Fork 500
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
ast: Out of bounds memory access crash in AST Vititor #8437
Comments
I cannot reproduce this, but I suspect this:
The crash hints access to non-existing source text. Can you try |
With a static The crash this time is at {__0={buf={ptr=NonNull(0x0000000000000000: 0x0000000000000000 <NULL>) cap=0 alloc=0x0000000000000000 <NULL> } ...} } With the following stack trace (this time also printed on exit): unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`
stack backtrace:
0: std::panicking::begin_panic_handler
at /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869\library/std\src\panicking.rs:665
1: core::panicking::panic_nounwind_fmt
at /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869\library/core\src\intrinsics\mod.rs:3535
2: core::panicking::panic_nounwind
at /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869\library/core\src\panicking.rs:223
3: core::slice::raw::from_raw_parts::precondition_check
at C:\Users\valja\.rustup\toolchains\1.84.0-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ub_checks.rs:69
4: core::slice::raw::from_raw_parts<oxc_ast::ast::js::Directive>
at C:\Users\valja\.rustup\toolchains\1.84.0-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ub_checks.rs:76
5: allocator_api2::stable::vec::impl$7::deref
at C:\Users\valja\.cargo\registry\src\index.crates.io-6f17d22bba15001f\allocator-api2-0.2.21\src\stable\vec\mod.rs:2557
6: oxc_ast::ast::js::Program::has_use_strict_directive
at C:\Users\valja\.cargo\registry\src\index.crates.io-6f17d22bba15001f\oxc_ast-0.44.0\src\ast_impl\js.rs:19
7: oxc_ast::generated::visit::walk::walk_program<test_runner::TypeVisitorImpl<core::iter::adapters::flatten::FlatMap<core::slice::iter::Iter<alloc::vec::Vec<test_runner::Assertion,alloc::alloc::Global> >,core::slice::iter::Iter<test_runner::Assertion>,test_ru
at C:\Users\valja\.cargo\registry\src\index.crates.io-6f17d22bba15001f\oxc_ast-0.44.0\src\generated\visit.rs:1347
8: oxc_ast::generated::visit::Visit::visit_program<test_runner::TypeVisitorImpl<core::iter::adapters::flatten::FlatMap<core::slice::iter::Iter<alloc::vec::Vec<test_runner::Assertion,alloc::alloc::Global> >,core::slice::iter::Iter<test_runner::Assertion>,test_
at C:\Users\valja\.cargo\registry\src\index.crates.io-6f17d22bba15001f\oxc_ast-0.44.0\src\generated\visit.rs:51
9: test_runner::TypeVisitor::run
at .\crates\test_runner\src\main.rs:56
10: test_runner::main
at .\crates\test_runner\src\main.rs:15
11: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
at C:\Users\valja\.rustup\toolchains\1.84.0-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:250
12: core::hint::black_box
at C:\Users\valja\.rustup\toolchains\1.84.0-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\hint.rs:389 I have also tried running the same code on Linux:
And on M1 Mac all 3 failed with the unsafe precondition check. Just pushed the code to a repo. Maybe this will help to reproduce it: https://github.com/valeneiko/oxc-crash |
I have found the cause for the crashes: Program node is allocated on the stack, and semantic holds a reference to it. The unrelated line that made it crash performs a bunch of stack allocations ovewriting the program node, and making data invalid. So when we try to access it later - program crashes. Normally Rust does not allow returning something that references a local var, but for some reason it does here. I am not sure why. But also I was expecting program node to get allocated in the allocator and not on the stack. Replacing that unrelated iteration with a simple stack allocation also reproduces the issue: - let _ = self.assertions.iter().flat_map(|x| x.iter().map(|x| x.expr)).collect::<String>();
+ let arr1 = [0usize; 1];
+ let mut arr = [0usize; 4096];
+ arr[4095] = arr1[0]; |
I believe the root of the problem is the lifetime extension in this code: oxc/crates/oxc_ast/src/generated/visit.rs Lines 42 to 47 in ab694b0
Please see #8461 for discussion of the broader problem, and why it causes this issue. On this specific issue, I think we can solve it fairly simply: Make No doubt this will cause compilation errors elsewhere in codebase from the borrow-checker. We'll need to fix them. The borrow-checker is correct. |
Summary
After adding some unrelated code to a function in my project
oxc::ast::Visit::visit_program
started crashing with out-of-bounds memory error:Stack Trace
Attaching a debugger to the program I got the following stack trace:
It seems that
self.directives
is NULL here:oxc/crates/oxc_ast/src/ast_impl/js.rs
Lines 17 to 20 in 01722f3
Code to reproduce (click to expand)
System Details
oxc: 0.44.0
os: Windows 11
The text was updated successfully, but these errors were encountered: