Skip to content

MDEV-37781 ASAN build crashes on deep query with low thread stack#5320

Open
vaintroub wants to merge 1 commit into
10.11from
MDEV-37781
Open

MDEV-37781 ASAN build crashes on deep query with low thread stack#5320
vaintroub wants to merge 1 commit into
10.11from
MDEV-37781

Conversation

@vaintroub

@vaintroub vaintroub commented Jul 1, 2026

Copy link
Copy Markdown
Member

check_stack_overrun() was compiled out under ASAN, so a deeply nested expression recursed in Item_func::fix_fields() until the stack was exhausted and the server crashed instead of reporting ER_STACK_OVERRUN_NEED_MORE.

Since MDEV-34533 (Monty) the stack usage seems to be accounted correctly under ASAN via my_get_stack_pointer(), so the check seems to works there too.

Fix:
Remove the #ifndef __SANITIZE_ADDRESS__ guard from check_stack_overrun()

Add a test for ER_STACK_OVERRUN_NEED_MORE

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request enables stack overrun checks in ASAN builds by removing the __SANITIZE_ADDRESS__ preprocessor guard in sql/sql_parse.cc, and introduces a new test case to verify thread stack overrun behavior. The reviewer pointed out that a comment in the new test file incorrectly mentions UBSAN instead of ASAN and suggested correcting it to avoid confusion.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +2 to +3
# MDEV-37781 UBSAN build crashes when executing long query after setting
# low thread stack

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The comment mentions UBSAN but the issue is related to ASAN (AddressSanitizer), as indicated by the PR title and the removal of the __SANITIZE_ADDRESS__ guard. It should be corrected to ASAN to avoid confusion.

# MDEV-37781 ASAN build crashes when executing long query after setting
#            low thread stack

Copilot AI left a comment

Copy link
Copy Markdown

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 an ASAN-specific crash where check_stack_overrun() was compiled out, allowing deep expression recursion (notably in Item_func::fix_fields()) to exhaust the thread stack and crash the server instead of raising ER_STACK_OVERRUN_NEED_MORE.

Changes:

  • Removes the #ifndef __SANITIZE_ADDRESS__ guard so check_stack_overrun() also runs under ASAN.
  • Adds an MTR test that forces a deep expression to validate the server returns ER_STACK_OVERRUN_NEED_MORE (with normalized numeric output).
  • Introduces a per-test .opt to run the test with a small thread stack (--thread-stack=256K).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
sql/sql_parse.cc Enables runtime stack overrun checks under ASAN by removing the compile-time guard.
mysql-test/main/thread_stack_overrun.test New regression test that triggers deep expression recursion and asserts ER_STACK_OVERRUN_NEED_MORE.
mysql-test/main/thread_stack_overrun.result Expected output for the new regression test (with numeric parts normalized).
mysql-test/main/thread_stack_overrun.opt Runs the test with a reduced thread stack to reliably hit the overrun path.

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

Comment thread mysql-test/main/thread_stack_overrun.test Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

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

check_stack_overrun() was compiled out under ASAN, so a deeply nested
expression recursed in Item_func::fix_fields() until the stack was
exhausted and the server crashed instead of reporting
ER_STACK_OVERRUN_NEED_MORE.

Since MDEV-34533 (Monty) the stack usage seems to be accounted correctly
under ASAN via my_get_stack_pointer(), so the check seems to works there
too.

Fix:
Remove the #ifndef __SANITIZE_ADDRESS__  guard from check_stack_overrun()

Add a test for ER_STACK_OVERRUN_NEED_MORE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants