MDEV-37781 ASAN build crashes on deep query with low thread stack#5320
MDEV-37781 ASAN build crashes on deep query with low thread stack#5320vaintroub wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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.
| # MDEV-37781 UBSAN build crashes when executing long query after setting | ||
| # low thread stack |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 socheck_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
.optto 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.
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
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