[SqlClient] Fix IndexOutOfRangeException #4139
Conversation
Fix `IndexOutOfRangeException` if trailing whitespace in an SQL statement aligns with an `ArrayPool` bucket boundary.
Remove unused code related to parsing SQL queries from OpenTelemetry.Instrumentation.StackExchangeRedis.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4139 +/- ##
==========================================
+ Coverage 72.89% 73.00% +0.10%
==========================================
Files 460 468 +8
Lines 18214 18239 +25
==========================================
+ Hits 13277 13315 +38
+ Misses 4937 4924 -13 Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Add PR number.
There was a problem hiding this comment.
Pull request overview
Fixes a length-sensitive IndexOutOfRangeException in the shared SQL parsing/sanitization logic used by database instrumentations, and removes now-unneeded SQL parser linkage from the StackExchangeRedis instrumentation.
Changes:
- Prevent summary-buffer overruns in
SqlProcessorby adding capacity checks/growth for the summary buffer and returning any additionally rented buffer to the pool. - Add regression coverage via unit + fuzz/property tests for bucket-aligned SQL lengths that previously could trigger the exception.
- Stop linking SQL query parsing code into StackExchangeRedis; compile SQL-parsing-related helper methods only for instrumentations that opt in via
INCLUDE_SQL_QUERY_PARSER.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/OpenTelemetry.Contrib.Shared.Tests/SqlProcessorTests.cs | Adds a targeted xUnit regression test around GetSanitizedSql behavior. |
| test/OpenTelemetry.Contrib.Shared.FuzzTests/SqlProcessorTests.cs | Adds a property test to exercise ArrayPool bucket-aligned statement lengths without throwing. |
| src/Shared/SqlProcessor.cs | Implements safe summary buffer appends with dynamic growth to avoid IndexOutOfRangeException. |
| src/Shared/DatabaseSemanticConventionHelper.cs | Wraps SQL-parser-dependent methods/usings in #if INCLUDE_SQL_QUERY_PARSER. |
| src/OpenTelemetry.Instrumentation.StackExchangeRedis/OpenTelemetry.Instrumentation.StackExchangeRedis.csproj | Removes compilation of shared SQL parser sources from StackExchangeRedis. |
| src/OpenTelemetry.Instrumentation.SqlClient/OpenTelemetry.Instrumentation.SqlClient.csproj | Defines INCLUDE_SQL_QUERY_PARSER to keep query parsing features enabled. |
| src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md | Documents the exception fix in Unreleased. |
| src/OpenTelemetry.Instrumentation.EntityFrameworkCore/OpenTelemetry.Instrumentation.EntityFrameworkCore.csproj | Defines INCLUDE_SQL_QUERY_PARSER to keep query parsing features enabled. |
| src/OpenTelemetry.Instrumentation.EntityFrameworkCore/CHANGELOG.md | Documents the exception fix in Unreleased. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4b912da
Changes
IndexOutOfRangeExceptionif trailing whitespace in an SQL statement aligns with anArrayPoolbucket boundary.I ran the benchmarks locally, and the differences are basically statistical noise.
Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)