Skip to content

fix: trim leading whitespace before stripping EXPLAIN/PROFILE prefix to avoid crash#4181

Open
imilinovic wants to merge 1 commit into
masterfrom
fix/query-crash
Open

fix: trim leading whitespace before stripping EXPLAIN/PROFILE prefix to avoid crash#4181
imilinovic wants to merge 1 commit into
masterfrom
fix/query-crash

Conversation

@imilinovic
Copy link
Copy Markdown
Contributor

@imilinovic imilinovic commented May 25, 2026

PrepareExplainQuery and PrepareProfileQuery stripped the keyword via query_string.substr(8) on the raw query. When the query had leading whitespace before EXPLAIN/PROFILE, this sliced into the inner query instead of removing the keyword — either failing the MG_ASSERT that expects a CypherQuery, or producing a Cypher parse error.

LTrim the raw query before the substr so the prefix is removed correctly regardless of leading whitespace.

@imilinovic imilinovic added this to the mg-v3.11.0 milestone May 25, 2026
@imilinovic imilinovic self-assigned this May 25, 2026
@imilinovic imilinovic added bug bug Docs - changelog only Docs - changelog only labels May 25, 2026
@imilinovic
Copy link
Copy Markdown
Contributor Author

imilinovic commented May 25, 2026

Tracking

Standard development

CI Testing Labels

  • Select the appropriate CI test labels (CI -build=build-name -test=test-suite)

Documentation checklist

  • Add the documentation label
  • Add the bug / feature label
  • Add the milestone for which this feature is intended
    • If not known, set for a later milestone
  • Write a release note, including added/changed clauses
    • Fix a bug where queries starting with whitespace and using EXPLAIN or PROFILE would cause a crash. #4181
  • [ Documentation PR link memgraph/documentation#XXXX ]
    • Is back linked to this development PR

@imilinovic imilinovic marked this pull request as ready for review May 25, 2026 09:28
Copilot AI review requested due to automatic review settings May 25, 2026 09:28
@imilinovic imilinovic requested a review from DavIvek May 25, 2026 09:31
@imilinovic imilinovic force-pushed the fix/query-crash branch 2 times, most recently from 31d2640 to fc0a56b Compare May 25, 2026 09:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a parsing/preprocessing edge case where leading whitespace before EXPLAIN/PROFILE caused incorrect prefix stripping (via substr(...)), leading to assertion failures or Cypher parse errors. It does so by trimming leading whitespace at the ParseQuery entry point, ensuring downstream logic can safely assume the query starts with the first significant token.

Changes:

  • Trim leading whitespace in ParseQuery before query stripping/caching and downstream processing.
  • Add Gherkin scenarios to ensure EXPLAIN and PROFILE work even when the query begins with whitespace/newlines.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/query/cypher_query_interpreter.cpp Trims leading whitespace once at parse entry to prevent bad EXPLAIN/PROFILE prefix slicing.
tests/gql_behave/tests/memgraph_V1/features/memgraph.feature Adds regression scenarios for leading-whitespace EXPLAIN and PROFILE.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@imilinovic imilinovic added this pull request to the merge queue May 26, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 26, 2026
@imilinovic imilinovic enabled auto-merge May 26, 2026 11:07
…4137)

PrepareExplainQuery and PrepareProfileQuery stripped the keyword via
query_string.substr(8) on the raw query. When the query had leading
whitespace before EXPLAIN/PROFILE, this sliced into the inner query
instead of removing the keyword — either failing the MG_ASSERT that
expects a CypherQuery, or producing a Cypher parse error.

LTrim the raw query before the substr so the prefix is removed
correctly regardless of leading whitespace.
@imilinovic imilinovic added this pull request to the merge queue May 26, 2026
@sonarqubecloud
Copy link
Copy Markdown

@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug bug Docs - changelog only Docs - changelog only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants