Skip to content

[Bug]: Panic: index out of bounds #2426

@markhilb

Description

@markhilb

What happened?

RUST_BACKTRACE=full sqruff lint test.sql
thread 'main' (3618389) panicked at /home/markus/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/sqruff-lib-0.35.4/src/rules/structure/st09.rs:237:53:
index out of bounds: the len is 0 but the index is 0
stack backtrace:
   0:     0x55bc88c47d52 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h93773fc827e3113d
   1:     0x55bc88c59cda - core::fmt::write::hed7b5c73d82ecb7c
   2:     0x55bc88c1c966 - std::io::Write::write_fmt::h6f0185aecf0ed75f
   3:     0x55bc88c29b79 - std::panicking::default_hook::{{closure}}::h2be84df4f189ae36
   4:     0x55bc88c299d9 - std::panicking::default_hook::hf0ea8939246f43a9
   5:     0x55bc88c29e6b - std::panicking::panic_with_hook::hb4bd9ac1123582a0
   6:     0x55bc88c29c38 - std::panicking::panic_handler::{{closure}}::hde00dd15f5637fe2
   7:     0x55bc88c24db9 - std::sys::backtrace::__rust_end_short_backtrace::hb72197fa777c1785
   8:     0x55bc88c104fd - __rustc[4425a7e20b4c8619]::rust_begin_unwind
   9:     0x55bc88c6392c - core::panicking::panic_fmt::ha59b517dd231f4da
  10:     0x55bc88c6377c - core::panicking::panic_bounds_check::h58fb035a90e7d970
  11:     0x55bc88556f54 - <sqruff_lib::rules::structure::st09::RuleST09 as sqruff_lib::core::rules::Rule>::eval::h08670d87b7ac15e5
  12:     0x55bc8856e74e - sqruff_lib::core::rules::crawl::{{closure}}::h3d01291792bf1575
  13:     0x55bc8857745f - <sqruff_lib::core::rules::crawlers::SegmentSeekerCrawler as sqruff_lib::core::rules::crawlers::BaseCrawler>::crawl::h687ecbbb267ba8a3
  14:     0x55bc8857761b - <sqruff_lib::core::rules::crawlers::SegmentSeekerCrawler as sqruff_lib::core::rules::crawlers::BaseCrawler>::crawl::h687ecbbb267ba8a3
  15:     0x55bc8857761b - <sqruff_lib::core::rules::crawlers::SegmentSeekerCrawler as sqruff_lib::core::rules::crawlers::BaseCrawler>::crawl::h687ecbbb267ba8a3
  16:     0x55bc8857761b - <sqruff_lib::core::rules::crawlers::SegmentSeekerCrawler as sqruff_lib::core::rules::crawlers::BaseCrawler>::crawl::h687ecbbb267ba8a3
  17:     0x55bc8857761b - <sqruff_lib::core::rules::crawlers::SegmentSeekerCrawler as sqruff_lib::core::rules::crawlers::BaseCrawler>::crawl::h687ecbbb267ba8a3
  18:     0x55bc884c1a31 - sqruff_lib::core::rules::crawl::h7dba4231f6214edf
  19:     0x55bc884efb87 - sqruff_lib::core::linter::core::Linter::lint_fix_parsed::h202cba90b3a6c964
  20:     0x55bc884edc7d - sqruff_lib::core::linter::core::Linter::lint_parsed::hc2dcc344730668a3
  21:     0x55bc8853670b - rayon::iter::plumbing::Folder::consume_iter::h42cfcce3a4626334
  22:     0x55bc88512b05 - rayon::iter::plumbing::bridge_producer_consumer::helper::h071d1f1100d7e404
  23:     0x55bc8857abe0 - rayon::iter::collect::collect_with_consumer::h508bc1e516a5a801
  24:     0x55bc884ec71b - sqruff_lib::core::linter::core::Linter::lint_paths::hbba0faede09228ab
  25:     0x55bc88362196 - sqruff_cli_lib::commands_lint::run_lint::h9aa7f881e8b5d343
  26:     0x55bc8836c457 - sqruff_cli_lib::run_with_args::h87d926e9576bc574
  27:     0x55bc8836aa69 - sqruff::main::hdd01d2e9894c0854
  28:     0x55bc8836ae23 - std::sys::backtrace::__rust_begin_short_backtrace::h81b648d5a2b9913a
  29:     0x55bc88368799 - std::rt::lang_start::{{closure}}::h529a3d27f6ba0e7b
  30:     0x55bc88c1e366 - std::rt::lang_start_internal::h9f282d832ae47dd5
  31:     0x55bc8836ad05 - main
  32:     0x7f8b893526c1 - <unknown>
  33:     0x7f8b893527f9 - __libc_start_main
  34:     0x55bc88360d35 - _start
  35:                0x0 - <unknown>

test.sql

SELECT
    *
FROM
    foo AS f
    INNER JOIN bar AS b ON b.period && f.period

.sqruff

[sqruff]
dialect = postgres
rules = all
# exclude_rules = structure.join_condition_order

The panic seems to be related to the rule structure.join_condition_order since excluding that rule does not trigger a panic, though I don't know if other rules might also be affected.

Version

sqruff 0.35.4

Checked in Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions