Skip to content

Fix SPARQL parser backtrack, executor memory leak, and add catch_unwind#180

Open
grparry wants to merge 1 commit intoruvnet:mainfrom
grparry:fix/sparql-deep-validation
Open

Fix SPARQL parser backtrack, executor memory leak, and add catch_unwind#180
grparry wants to merge 1 commit intoruvnet:mainfrom
grparry:fix/sparql-deep-validation

Conversation

@grparry
Copy link

@grparry grparry commented Feb 17, 2026

Summary

Three additional hardening fixes for the SPARQL subsystem, building on PR #172:

  • Parser backtrack fix: Replace hardcoded saturating_sub(6) with a saved_pos variable. The old backtrack assumed all update keywords are 6 characters, but LOAD (4), DROP (4), and CLEAR (5) are shorter, causing incorrect parse positions for those statements.

  • Executor memory leak fix: Change SparqlContext.default_graph from Option<&'a str> to Option<String> and remove Box::leak calls in the GraphPattern::Graph handler. Each GRAPH clause previously leaked a String allocation that was never freed.

  • catch_unwind safety net: Wrap ruvector_sparql() parse/execute/format in std::panic::catch_unwind so that panics from non-empty but malformed queries are converted to PostgreSQL ERROR messages instead of crashing the backend. This complements the empty-query check from fix: HNSW index bugs, agent/SPARQL crashes, lru security #172 by catching deeper failures.

Closes #167

Test plan

  • Verify LOAD, CLEAR, DROP SPARQL update statements parse correctly (parser backtrack)
  • Verify GRAPH <iri> { ... } queries don't leak memory (executor fix)
  • Verify malformed non-empty SPARQL queries return ERROR, not SIGABRT (catch_unwind)
  • Verify existing SPARQL tests still pass

🤖 Generated with Claude Code

Three additional hardening fixes for the SPARQL subsystem, building on
PR ruvnet#172:

1. Parser: replace hardcoded saturating_sub(6) with saved_pos variable.
   The old backtrack assumed all update keywords are 6 chars, but LOAD,
   DROP, and CLEAR are 4-5 chars, causing incorrect parse positions.

2. Executor: change default_graph from Option<&'a str> to Option<String>
   and remove Box::leak calls in the GraphPattern::Graph handler. Each
   GRAPH clause previously leaked a String allocation that was never freed.

3. Operators: wrap ruvector_sparql parse/execute/format in catch_unwind
   so that panics from non-empty but malformed queries are converted to
   PostgreSQL ERROR messages instead of crashing the backend.

Closes ruvnet#167

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

ruvector_list_agents() and ruvector_sparql_json() crash PostgreSQL backend

1 participant