Skip to content

fix(safe-mode): read MySQL, MariaDB and TiDB executable comments as each server runs them - #3791

Merged
datlechin merged 3 commits into
mainfrom
fix/3784-safe-mode-mysql-executable-comments
Oct 22, 2026
Merged

datlechin merged 3 commits into
mainfrom
fix/3784-safe-mode-mysql-executable-comments

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • New SQLExecutableCommentReadings: the texts a MySQL, MariaDB or TiDB server may run from a statement, one per server family and version threshold. A skipped or plain comment is blanked, a run comment is unwrapped.
  • Modelled per server: /*!NNNNN skipped above the server's version past one nested /* */, MariaDB's /*!50700../*!99999 band, 5 or 6 version digits, /*M! plain on MySQL, /*T! run on TiDB, /*m! plain everywhere, OceanBase's flat retry.
  • Every gate reads all of them through SQLLexicalReadings.lexings(of:) and keeps the worst: Safe Mode levels, MCP, AI chat, AppleScript, the CLI, dashboard tiles, iOS, catalog refresh, row write refusal.
  • A text with more than 32 distinct versions is read as its worst case.
  • When no comment can move a statement boundary, each statement is read under its own comments only, so a mysqldump costs about 4 scans instead of one per version.
  • The lexer takes only /*! and /*M! as executable, and lexes a run body as code: nested comments, # and -- , no second level. The PluginKit lexer matches.
  • File markers match across comments and spaces (INTO/**/OUTFILE, LOAD_FILE (), and ALTER TABLE ... TRUNCATE PARTITION is destructive.
  • MySQLSessionFootprint reads the statement behind a version comment a server may skip.
  • SQL import reads a run conditional comment's body as code, and reads mysqldump's DELIMITER ;;.
  • Probe apple/scripts/probes/check-mysql-executable-comments.sh: passes on MySQL 8.0.46 and 8.4.11, MariaDB 11.4.13, TiDB 8.5.1.

Test plan

  • SQLExecutableCommentReadingsTests: each measured text drops the table under exactly the servers that dropped it, and every server's statements are among the texts the gates read.
  • ExecutionGateExecutableCommentTests: each executable comment form hiding a DROP is refused in Read-Only and confirmed as destructive at every other Safe Mode level, on MySQL and MariaDB.
  • New cases in QueryClassifierExecutableCommentTests, ExternalStatementGateExecutableCommentTests, DashboardTilePolicyTests, SQLWriteClassifierTests, CatalogChangeClassifierTests, SQLFileParserTests, SQLStatementSplittingTests, SQLLexicalFeatureMappingTests, MySQLSessionFootprintTests.
  • Unit plan and the TableProCore suites pass.

Fixes #3784

@datlechin datlechin added backport release/0.82 Merged into main; pick onto release/0.82 backport release/0.83 Merged into main; pick onto release/0.83 bug Something isn't working labels Oct 22, 2026
@datlechin
datlechin enabled auto-merge (squash) October 22, 2026 14:54
@datlechin
datlechin merged commit 502c842 into main Oct 22, 2026
8 checks passed
@datlechin
datlechin deleted the fix/3784-safe-mode-mysql-executable-comments branch October 22, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport release/0.82 Merged into main; pick onto release/0.82 backport release/0.83 Merged into main; pick onto release/0.83 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS: Safe Mode misreads version-gated and lowercase MySQL executable comments

1 participant