codeant-ai-for-open-source[bot] commented on code in PR #42598:
URL: https://github.com/apache/superset/pull/42598#discussion_r3706490912
##########
superset/sql/parse.py:
##########
@@ -1996,6 +1996,22 @@ def extract_tables_from_statement(
}
+def count_referenced_tables(statement: str, dialect: Dialects | str | None) ->
int:
+ """
+ Count the distinct tables referenced by a raw SQL string.
+
+ Falls back to a conservative count of 1 (i.e. "not multi-table") if the
+ statement can't be parsed, since callers gating multi-table-only behavior
+ on this count should default to treating an unparseable statement as a
+ single table.
+ """
+ try:
+ parsed = sqlglot.parse_one(statement, dialect=dialect)
+ return len(extract_tables_from_statement(parsed, dialect))
Review Comment:
**Suggestion:** The new helper sends the complete raw statement directly to
`sqlglot.parse_one` without calling `_check_script_length`. Since this helper
is invoked for every metadb execution path, an oversized SQL statement can
bypass the module-wide `SQL_MAX_PARSE_LENGTH` protection and cause excessive
parser CPU or memory usage. Apply the existing length check before parsing, or
route this through the bounded parser helper. [security]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ MetaDB statement classification bypasses `SQL_MAX_PARSE_LENGTH`.
- ⚠️ Oversized SQL can consume parser CPU and memory.
- ⚠️ Every `superset://` execution invokes this classification path.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=0627bfc167924f0fa6eb5c80f1d6c5b0&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=0627bfc167924f0fa6eb5c80f1d6c5b0&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/sql/parse.py
**Line:** 2010:2010
**Comment:**
*Security: The new helper sends the complete raw statement directly to
`sqlglot.parse_one` without calling `_check_script_length`. Since this helper
is invoked for every metadb execution path, an oversized SQL statement can
bypass the module-wide `SQL_MAX_PARSE_LENGTH` protection and cause excessive
parser CPU or memory usage. Apply the existing length check before parsing, or
route this through the bounded parser helper.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42598&comment_hash=9f2c98177e47080c2f0d27dd1d840ee6dc7b1f29b729de7ef6c8d0c6ff20ed85&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42598&comment_hash=9f2c98177e47080c2f0d27dd1d840ee6dc7b1f29b729de7ef6c8d0c6ff20ed85&reaction=dislike'>👎</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]