VHDL-LS / rust_hdl

Other
340 stars 65 forks source link

Parser stack overflow on big strings #133

Closed jeanthom closed 2 years ago

jeanthom commented 2 years ago

I noticed on a specific code base that when you concatenate far too much strings together it makes the parser crash:

[jeanthomas@computer rust_hdl]$ target/debug/vhdl_lang --config long_str_reproducer/vhdl_ls.toml 
log: Loaded Installation configuration file: /home/jeanthomas/Documents/rust_hdl/target/debug/../../vhdl_libraries/vhdl_ls.toml

thread '<unknown>' has overflowed its stack
fatal runtime error: stack overflow
Abandon (core dumped)

Here's the crash backtrace:

(gdb) bt
#0  0x00005555556b37f6 in core::alloc::layout::size_align<core::mem::maybe_uninit::MaybeUninit<vhdl_lang::data::source::WithPos<vhdl_lang::ast::Expression>>>
    () at /builddir/build/BUILD/rustc-1.62.1-src/library/core/src/alloc/layout.rs:13
#1  0x00005555556b3e7a in core::alloc::layout::Layout::new<core::mem::maybe_uninit::MaybeUninit<vhdl_lang::data::source::WithPos<vhdl_lang::ast::Expression>>> () at /builddir/build/BUILD/rustc-1.62.1-src/library/core/src/alloc/layout.rs:128
#2  0x000055555569e5e7 in alloc::boxed::{impl#1}::new_uninit_in<vhdl_lang::data::source::WithPos<vhdl_lang::ast::Expression>, alloc::alloc::Global> (
    alloc=...) at /builddir/build/BUILD/rustc-1.62.1-src/library/alloc/src/boxed.rs:427
#3  0x00005555556a20d3 in alloc::boxed::{impl#12}::clone<vhdl_lang::data::source::WithPos<vhdl_lang::ast::Expression>, alloc::alloc::Global> (
    self=0x7fffdc0ec628) at /builddir/build/BUILD/rustc-1.62.1-src/library/alloc/src/boxed.rs:1237
#4  0x000055555568452d in vhdl_lang::ast::{impl#86}::clone (self=0x7fffdc0ec620) at vhdl_lang/src/ast.rs:245
#5  0x000055555569ad8c in vhdl_lang::data::source::{impl#51}::clone<vhdl_lang::ast::Expression> (self=0x7fffdc0ec620) at vhdl_lang/src/data/source.rs:278
#6  0x0000555555696577 in alloc::alloc::{impl#2}::write_clone_into_raw<vhdl_lang::data::source::WithPos<vhdl_lang::ast::Expression>> (self=0x7fffdc0ec620, 
    target=0x7fffdc1baa00) at /builddir/build/BUILD/rustc-1.62.1-src/library/alloc/src/alloc.rs:428
#7  0x00005555556a2122 in alloc::boxed::{impl#12}::clone<vhdl_lang::data::source::WithPos<vhdl_lang::ast::Expression>, alloc::alloc::Global> (
    self=0x7fffdc0ec708) at /builddir/build/BUILD/rustc-1.62.1-src/library/alloc/src/boxed.rs:1239
#8  0x000055555568452d in vhdl_lang::ast::{impl#86}::clone (self=0x7fffdc0ec700) at vhdl_lang/src/ast.rs:245
#9  0x000055555569ad8c in vhdl_lang::data::source::{impl#51}::clone<vhdl_lang::ast::Expression> (self=0x7fffdc0ec700) at vhdl_lang/src/data/source.rs:278
#10 0x0000555555696577 in alloc::alloc::{impl#2}::write_clone_into_raw<vhdl_lang::data::source::WithPos<vhdl_lang::ast::Expression>> (self=0x7fffdc0ec700, 
    target=0x7fffdc1ba9a0) at /builddir/build/BUILD/rustc-1.62.1-src/library/alloc/src/alloc.rs:428
#11 0x00005555556a2122 in alloc::boxed::{impl#12}::clone<vhdl_lang::data::source::WithPos<vhdl_lang::ast::Expression>, alloc::alloc::Global> (
    self=0x7fffdc0ec7e8) at /builddir/build/BUILD/rustc-1.62.1-src/library/alloc/src/boxed.rs:1239
#12 0x000055555568452d in vhdl_lang::ast::{impl#86}::clone (self=0x7fffdc0ec7e0) at vhdl_lang/src/ast.rs:245
#13 0x000055555569ad8c in vhdl_lang::data::source::{impl#51}::clone<vhdl_lang::ast::Expression> (self=0x7fffdc0ec7e0) at vhdl_lang/src/data/source.rs:278
#14 0x0000555555696577 in alloc::alloc::{impl#2}::write_clone_into_raw<vhdl_lang::data::source::WithPos<vhdl_lang::ast::Expression>> (self=0x7fffdc0ec7e0, 
    target=0x7fffdc1ba940) at /builddir/build/BUILD/rustc-1.62.1-src/library/alloc/src/alloc.rs:428
#15 0x00005555556a2122 in alloc::boxed::{impl#12}::clone<vhdl_lang::data::source::WithPos<vhdl_lang::ast::Expression>, alloc::alloc::Global> (
    self=0x7fffdc0ec8c8) at /builddir/build/BUILD/rustc-1.62.1-src/library/alloc/src/boxed.rs:1239
#16 0x000055555568452d in vhdl_lang::ast::{impl#86}::clone (self=0x7fffdc0ec8c0) at vhdl_lang/src/ast.rs:245
#17 0x000055555569ad8c in vhdl_lang::data::source::{impl#51}::clone<vhdl_lang::ast::Expression> (self=0x7fffdc0ec8c0) at vhdl_lang/src/data/source.rs:278
#18 0x0000555555696577 in alloc::alloc::{impl#2}::write_clone_into_raw<vhdl_lang::data::source::WithPos<vhdl_lang::ast::Expression>> (self=0x7fffdc0ec8c0, 
    target=0x7fffdc1ba8e0) at /builddir/build/BUILD/rustc-1.62.1-src/library/alloc/src/alloc.rs:428

Reproducer code: long_str_reproducer.zip

jeanthom commented 2 years ago

Moving this issue to my fork