Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-42347

Server crash (SIGSEGV) in handler::ha_delete_all_rows() called from TABLE::insert_all_rows_into_tmp_table() for two mutually recursive CTEs

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 13.3
    • None
    • Optimizer
    • None

    Description

      Problem

      A query with two mutually recursive CTEs (the "ancestors of a person" example, where ancestor_couple_ids reads coupled_ancestors and coupled_ancestors reads ancestor_couple_ids) crashes the server with SIGSEGV in handler::ha_delete_all_rows(), called from TABLE::insert_all_rows_into_tmp_table(). The table folks is empty.

      How to repeat

      Fresh server, default settings:

      create table folks(id int, name char(32), dob date, father int, mother int);
      WITH RECURSIVE ancestor_couple_ids (h_id, w_id) AS (
        SELECT a.father, a.mother FROM coupled_ancestors a WHERE a.father IS NOT NULL AND a.mother IS NOT NULL
        UNION
        SELECT a.father, a.mother FROM coupled_ancestors a WHERE a.father IS NOT NULL AND a.mother IS NOT NULL
      ), coupled_ancestors (id, name, dob, father, mother) AS (
        SELECT * FROM folks WHERE name = 'Me'
        UNION ALL
        SELECT p.* FROM folks p, ancestor_couple_ids fa WHERE p.id = fa.h_id
        UNION ALL
        SELECT p.* FROM folks p, ancestor_couple_ids ma WHERE p.id = ma.w_id
      )
      SELECT h.name, h.dob, w.name, w.dob
      FROM ancestor_couple_ids c, coupled_ancestors h, coupled_ancestors w
      WHERE c.h_id = h.id AND c.w_id = w.id;

      I started a fresh server on an empty data directory for each run (13.3.0 main, commit 392818112, --no-defaults, TCP) and ran the two statements once. Results:

      • Debug build with assertions: SIGSEGV (signal 11) in 3 of 3 runs. No assertion message is printed before the crash.
      • Optimized build (with coverage instrumentation, no DBUG assertions): signal 11 in 3 of 3 runs.
      • ASan/UBSan build: 3 of 3 runs stop with storage/heap/hp_clear.c:27:9: runtime error: member access within null pointer of type 'HP_INFO' (the build uses -fno-sanitize-recover=undefined, so the server stops there).

      The crash does not depend on the table definition details I varied (one run each on the debug build): without charset=latin1, with engine=MyISAM, and with three rows in folks ((1,'Me','2000-01-01',2,3),(2,'Dad','1970-01-01',NULL,NULL),(3,'Mom','1972-01-01',NULL,NULL)) the server crashes as well.

      Actual result

      Debug and optimized builds, the top of the stack:

      handler::ha_delete_all_rows()
      TABLE::insert_all_rows_into_tmp_table(THD*, TABLE*, TMP_TABLE_PARAM*, bool)

      and the ASan/UBSan run reports the null HP_INFO access in hp_clear() (storage/heap/hp_clear.c:27). I did not capture a stack for the ASan/UBSan run and no longer stack for the other two.

      Notes

      • The tested source tree contains a small local change of the test harness in sql/sql_parse.cc (24 lines: calls to a coverage hook around dispatch_command() in do_command()). The calls are compiled into the debug and the optimized build and are not compiled into the ASan/UBSan build, which crashes the same way. The change does not touch the optimizer or the heap engine.
      • I did not trace why the heap table handler has no HP_INFO at that point, and I did not test other branches or releases.

      Attachments

        Activity

          People

            Unassigned Unassigned
            hacker_zheng Wang Zheng
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.