Details
-
Bug
-
Status: In Review (View Workflow)
-
Critical
-
Resolution: Unresolved
-
10.11
Description
While importing MariaDB 11.8.10 into Debian, I noticed this test failing on armhf:
main.lotofstack w8 [ fail ]
|
Test ended at 2026-11-17 01:07:46
|
|
|
CURRENT_TEST: main.lotofstack
|
mysqltest: At line 220: query 'explain extended select * from json_table('[{}]', '\$[*]' columns ($(repeat("nested path '\$' columns (", $n)) a int path '\$.a' $(repeat(")", $n)))) jt' succeeded - should have failed with error ER_STACK_OVERRUN_NEED_MORE (1436)...
|
|
|
The result from queries just before the failure was:
|
< snip >
|
insert t2 values (@g);
|
select st_astext(@g);
|
select st_asgeojson(@g);
|
select st_envelope(@g);
|
select st_area(@g);
|
select st_length(@g);
|
select st_dimension(@g);
|
select st_boundary(@g);
|
drop table t1, t2;
|
#
|
# MDEV-41804 deeply nested ROWs crash
|
#
|
select $(repeat("row(1,", $n)) 1 $(repeat(")", $n));
|
select 1;
|
1
|
1
|
#
|
# MDEV-40847 Server crash on EXPLAIN EXTENDED or CREATE VIEW of a deeply nested JSON_TABLE
|
#
|
explain extended select * from json_table('[{}]', '\$[*]' columns ($(repeat("nested path '\$' columns (", $n)) a int path '\$.a' $(repeat(")", $n)))) jt;
|
This is a new test introduced in commit c746ca3e2d081b1b8a797f86c41cdbfbc82215b0
Author: Sergei Golubchik <serg@mariadb.org>
|
Date: Wed Nov 4 16:41:37 2026 +0100
|
|
|
MDEV-40847 Server crash on EXPLAIN EXTENDED or CREATE VIEW of a deeply nested JSON_TABLE
|
|
* check the stack in Json_table_nested_path::print(), it recurses
|
once per NESTED PATH level
|
* don't save a view definition if printing it failed
|
* don't push the EXPLAIN EXTENDED note if printing it failed
|
|
Assisted-by: Claude:claude-opus-5-5
|
Perhaps it was never tested on a 32-bit system?
Claude says this is the root cause of the failure:
The guard added by c746ca3e2d0 is a byte limit, but the test uses a fixed recursion depth (5000). Those two only line up on 64-bit x86,
where a Json_table_nested_path::print() activation is larger than ~57 bytes. On 32-bit armhf the frame is smaller, so 5000 levels stay
under the limit, the statement completes, and --error ER_STACK_OVERRUN_NEED_MORE fails.Numbers
check_stack_overrun() (sql/sql_parse.cc:7374) trips when
```
stack_used >= my_thread_stack_size - margin
```with margin = STACK_MIN_SIZE = 16000 (sql/sql_const.h:186).
my_thread_stack_size does not end up at the mysys/my_init.c:62 initializer value (64 KiB on 32-bit); init_variables() in
mysys/my_getopt.c:282/1517 applies the sysvar default from sql/sys_vars.cc:3352, which is DEFAULT_THREAD_STACK (include/my_pthread.h:669)
= 292*1024 = 299008 on ordinary, non-ASAN/UBSAN builds on every architecture.So the recursion must consume
```
299008 - 16000 = 283008 bytes
283008 / 5000 = 56.6 bytes per nesting level
```x86_64 frame > 56.6 B → guard fires before level 5000 → test passes.
32-bit ARM frame < 56.6 B (4-byte pointers, fewer callee-saved regs to spill) → 5000 levels use < 283 KiB, fits in the 292 KiB thread
stack → guard never fires → query succeeds → test fails.That also explains why
MDEV-41804's $n=4000 row(…) case still passes on armhf: those parser/fix_fields() frames are far larger per level.Confirming it without arm hardware
thread_stack is read-only, but it can be set at server start. On amd64, run
```sh
./mtr -mysqld=-thread-stack=524288 main.lotofstack
```The threshold becomes ~508 KiB, 5000 levels no longer overrun, and you should reproduce the armhf failure. Conversely,
-thread-stack=131072 (the allowed minimum) makes the same $n=5000 overrun comfortably on both 32and 64-bit.So the Error 1436 block in the failure log is the expected .result text; the actual statement returned success.
How the test should be written
Fixed depth is inherently compiler/arch dependent. Options, in rough order of preference:
1. Scale depth with the limit, like mysql-test/main/thread_stack_overrun.test does (“each recursion level consumes at least one byte, so
use @@global.thread_stack terms”). For this case let $n = @@global.thread_stack; is guaranteed to overrun, but it builds a ~7 MB query
and 299k parser levels, so it may be too heavy — a divisor with a conservative minimum frame size (e.g. 16 B) is a compromise.
2. Force a small stack for the test via mysql-test/main/lotofstack-master.opt containing --thread-stack=131072, keeping $n=5000. Threshold
drops to 115008 B, so 5000 levels overrun even with a ~24 B frame. Downside: the smaller stack applies to the whole file (all its other
cases are also “expect overrun”, so it is probably harmless).
3. Keep 5000 but make it a separate test file with its own .opt, so the rest of lotofstack keeps the default stack.A fix should go upstream (the test is shipped in 10.11.20/11.4.14/11.8.10/12.3.4), and this is exactly the kind of case where a 32-bit CI
run is needed.
Attachments
Issue Links
- is blocked by
-
MDEV-42466 Windows threadpool crashes with STATUS_STACK_OVERFLOW when thread_stack is a multiple of 64 KiB
-
- Open
-