Skip to content

Fix index out of bounds panic in ST09 for non-standard comparison ope…#2427

Open
benfdking wants to merge 3 commits intomainfrom
claude/fix-index-bounds-panic-Wp8R1
Open

Fix index out of bounds panic in ST09 for non-standard comparison ope…#2427
benfdking wants to merge 3 commits intomainfrom
claude/fix-index-bounds-panic-Wp8R1

Conversation

@benfdking
Copy link
Copy Markdown
Collaborator

…rators

The && (overlap) operator in PostgreSQL is parsed as a ComparisonOperator but contains AmpersandSegment children instead of RawComparisonOperator children. ST09 assumed raw_comparison_operators was non-empty when swapping column order, causing a panic on index 0 of an empty vec.

Add an emptiness check before accessing raw_comparison_operators[0].

Fixes #2426

https://claude.ai/code/session_01QzckwNiRjStjnS9c7BZRHQ

…rators

The `&&` (overlap) operator in PostgreSQL is parsed as a ComparisonOperator
but contains AmpersandSegment children instead of RawComparisonOperator
children. ST09 assumed raw_comparison_operators was non-empty when swapping
column order, causing a panic on index 0 of an empty vec.

Add an emptiness check before accessing raw_comparison_operators[0].

Fixes #2426

https://claude.ai/code/session_01QzckwNiRjStjnS9c7BZRHQ
@benfdking
Copy link
Copy Markdown
Collaborator Author

The problem is in fact the fact that we are not parsing the thing correctly.

@github-actions
Copy link
Copy Markdown
Contributor

Benchmark for f8adaf3

Click to view benchmark
Test Base PR %
DepthMap::from_parent 51.4±0.88µs 53.0±0.58µs +3.11%
fix_complex_query 11.7±0.06ms 11.6±0.21ms -0.85%
fix_superlong 167.0±10.23ms 172.1±10.06ms +3.05%
parse_complex_query 4.1±0.06µs 4.2±0.03µs +2.44%
parse_expression_recursion 7.3±0.05µs 7.0±0.08µs -4.11%
parse_simple_query 1057.1±18.98ns 1046.7±20.27ns -0.98%

claude and others added 2 commits March 16, 2026 14:20
Instead of just guarding against the empty index, properly handle
non-standard comparison operators like && (overlap), &> etc. by
extracting the operator string and checking it against a whitelist
of reorderable operators. This matches SQLFluff's _REORDERABLE_OPERATORS
approach in their ST09 rule.

https://claude.ai/code/session_01QzckwNiRjStjnS9c7BZRHQ
@github-actions
Copy link
Copy Markdown
Contributor

Benchmark for c36594b

Click to view benchmark
Test Base PR %
DepthMap::from_parent 51.8±1.92µs 52.2±1.27µs +0.77%
fix_complex_query 12.0±0.09ms 11.8±0.13ms -1.67%
fix_superlong 200.1±7.38ms 196.0±7.31ms -2.05%
parse_complex_query 4.2±0.04µs 4.2±0.04µs 0.00%
parse_expression_recursion 7.2±0.09µs 7.1±0.09µs -1.39%
parse_simple_query 1068.1±17.90ns 1056.8±34.23ns -1.06%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Panic: index out of bounds

2 participants