Skip to content

Fix raw query escaping#60

Merged
StpMax merged 1 commit into
mainfrom
fix-raw-query-escape2
Aug 5, 2025
Merged

Fix raw query escaping#60
StpMax merged 1 commit into
mainfrom
fix-raw-query-escape2

Conversation

@ea-rus

@ea-rus ea-rus commented Aug 4, 2025

Copy link
Copy Markdown
Contributor

Alternative to #59

@ea-rus ea-rus requested a review from StpMax August 4, 2025 15:22
@github-actions

github-actions Bot commented Aug 4, 2025

Copy link
Copy Markdown

Coverage

Coverage Report
FileStmtsMissCoverMissing
mindsdb_sql_parser
   __about__.py10100%1–10
   __init__.py1192282%44, 48, 53, 98, 115, 139–158, 165–166
   lexer.py2802192%368, 370, 372, 384, 386, 388, 394–412
   logger.py19479%14, 17, 23, 26
   parser.py11073297%129, 133, 288, 313, 419, 605, 622, 646–647, 868, 922, 999, 1100, 1153, 1163, 1202–1203, 1232, 1243, 1326, 1402, 1441, 1477, 1670–1671, 1846–1847, 2023, 2031, 2084–2087
   utils.py46491%73–79
mindsdb_sql_parser/ast
   base.py36586%13, 28, 31, 46, 51
   create.py801285%23–31, 92–97
   drop.py52296%10, 13
   insert.py63494%39–41, 46
   show.py48198%18
   update.py53591%40–42, 75–76
mindsdb_sql_parser/ast/mindsdb
   knowledge_base.py97199%80
mindsdb_sql_parser/ast/select
   case.py37197%22
   constant.py36197%23
   data.py11464%10–12, 15, 19
   identifier.py831187%56, 104–112, 122
   native_query.py13192%25
   operation.py139497%57, 66, 178, 202
   parameter.py15287%17, 20
   select.py109397%160–165
   star.py12283%8–9
TOTAL339215296% 

Tests Skipped Failures Errors Time
303 0 💤 0 ❌ 0 🔥 13.027s ⏱️

@entelligence-ai-pr-reviews

Copy link
Copy Markdown

Review Summary

🏷️ Draft Comments (2)

Skipped posting 2 draft comments that were valid but scored below your review threshold (>13/15). Feel free to update them here.

mindsdb_sql_parser/lexer.py (1)

391-412: error method splits the entire input text on every error, causing O(n) time and memory usage per error for large queries; this can severely degrade performance for large SQL scripts.

📊 Impact Scores:

  • Production Impact: 3/5
  • Fix Specificity: 4/5
  • Urgency Impact: 2/5
  • Total Score: 9/15

🤖 AI Agent Prompt (Copy & Paste Ready):

Optimize the error reporting in mindsdb_sql_parser/lexer.py, lines 391-412. The current `error` method splits the entire input text on every error, which is O(n) in time and memory and can severely degrade performance for large SQL scripts. Refactor it to only extract the relevant lines around the error position without splitting the whole text. Preserve the error message format and code context.

mindsdb_sql_parser/parser.py (1)

2009-2009: quote_string and dquote_string use unsafe .replace() logic for unescaping, allowing crafted input to break out of string context and potentially enable SQL injection or parser confusion.

📊 Impact Scores:

  • Production Impact: 4/5
  • Fix Specificity: 4/5
  • Urgency Impact: 3/5
  • Total Score: 11/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sql_parser/parser.py, line 2009, the current `quote_string` implementation uses `.replace()` to unescape both backslash and double quote escapes, which is unsafe and can allow crafted input to break out of string context, leading to SQL injection or parser confusion. Update the code to only unescape doubled single quotes (the standard SQL escape for single-quoted strings), and do not process backslash escapes or double quote escapes. The fix should securely strip the outer single quotes and replace only doubled single quotes with a single quote. Apply this change at line 2009.

@StpMax StpMax mentioned this pull request Aug 5, 2025
@StpMax StpMax merged commit a2b697f into main Aug 5, 2025
14 checks passed
@StpMax StpMax deleted the fix-raw-query-escape2 branch August 5, 2025 12:12
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.

2 participants