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

Stack-buffer-overflow write in dynamic-column backwritenum on numeric key ≥ 7 digits

    XMLWordPrintable

Details

    • Bug
    • Status: In Review (View Workflow)
    • Critical
    • Resolution: Unresolved
    • 10.11, 13.3
    • 10.11
    • Dynamic Columns
    • MariaDB 13.3.0-MariaDB-asan-debug, self-built from commit 392818112 with -DWITH_ASAN=ON -DCMAKE_BUILD_TYPE=Debug; Linux x86_64

    Description

      COLUMN_GET with a numeric dynamic-column key of 7 or more decimal digits causes a stack-buffer-overflow write detected by AddressSanitizer. The server crashes.

      Reproduce (non-superuser)

      SELECT COLUMN_GET(COLUMN_CREATE('a',1), 1000000 AS INT);

      Any numeric key with ≥ 7 decimal digits triggers it (6-digit keys are safe; 7–10 digits overflow by 1–4 bytes). Also via COLUMN_EXISTS(blob, big_num) and AS CHAR.

      Actual result

      AddressSanitizer: stack-buffer-overflow, WRITE of size 1, underflowing a 6-byte stack buffer:

      #0 backwritenum                mysys/ma_dyncol.c:2100
      #1 find_column                 mysys/ma_dyncol.c:2142
      #2 dynamic_column_get_internal mysys/ma_dyncol.c:2325
      #4 Item_dyncol_get::get_dyn_value  sql/item_strfunc.cc:5248

      Root cause

      find_column() renders the lookup key into char nmkeybuff[DYNCOL_NUM_CHAR] (DYNCOL_NUM_CHAR=6, sized for the 2-byte stored key) via backwritenum(), which writes decimal digits backward from the end of the buffer. The SQL path validates only 0..INT_MAX (up to 10 digits), so keys > 999999 write before the buffer.

      Expected result

      The statement should return NULL or raise an error; the server must not crash.

      Severity assessment

      HIGH — out-of-bounds WRITE on the stack. Reachable by any user with SELECT privilege.

      Attachments

        Activity

          People

            sanja Oleksandr Byelkin
            imchifan 刘启帆
            Oleksandr Byelkin Oleksandr Byelkin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 0d
                0d
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified

                Git Integration

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