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

Large ORDER BY and GROUP BY positions wrap to valid columns or truncated diagnostics

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 10.11, 11.4, 11.8, 12.3, 13.1, 12.3.3
    • 10.11, 11.4, 11.8, 12.3, 13.1
    • Optimizer
    • None
    • Linux x86_64, MariaDB.org Ubuntu 24.04 binary distribution

    Description

      MariaDB 12.3.3 on Linux x86_64 accepts the invalid positional selector 4294967297 as position 1 in ORDER BY, GROUP BY, UNION ordering, and a prepared parameter. At the adjacent boundary, 4294967296 is rejected but reported as column 0 instead of preserving the supplied value.

      This occurs when positional ORDER BY or GROUP BY selectors reach the 32-bit wraparound boundary, including through prepared parameters.

      Reproducer

      Create the following files.

      control.sql establishes that position 2 is invalid for a one-column result:

      SELECT 7 AS value ORDER BY 2;

      order.sql uses the oversized position in a literal ORDER BY:

      SELECT 7 AS value ORDER BY 4294967297;

      group.sql uses the same position in GROUP BY:

      SELECT 7 AS value GROUP BY 4294967297;

      union.sql applies it to a global UNION ordering clause:

      SELECT 7 AS value UNION ALL SELECT 3 ORDER BY 4294967297;

      prepared.sql supplies the position as an integer prepared parameter, followed by the valid position 1 as a control:

      PREPARE s FROM 'SELECT 7 AS value ORDER BY ?';
      SET @pos=4294967297;
      EXECUTE s USING @pos;
      SET @pos=1;
      EXECUTE s USING @pos;
      DEALLOCATE PREPARE s;
      SET @pos=NULL;

      diagnostic.sql checks the adjacent boundary value:

      SELECT 7 AS value ORDER BY 4294967296;

      Run each file separately with the MariaDB client:

      mariadb < control.sql
      mariadb < order.sql
      mariadb < group.sql
      mariadb < union.sql
      mariadb < prepared.sql
      mariadb < diagnostic.sql

      Observed behavior

      The control rejects position 2 and identifies it correctly:

      ERROR 1054 (42S22): Unknown column '2' in 'ORDER BY'

      The statements using 4294967297 execute successfully. Their result values are:

      order.sql:     7
      group.sql:     7
      union.sql:     3
                     7
      prepared.sql:  7
                     7

      The first prepared result is from 4294967297 and the second is from valid position 1. The diagnostic statement fails, but truncates the supplied position to 0:

      ERROR 1054 (42S22): Unknown column '0' in 'ORDER BY'

      Expected behavior

      A one-column result has no position 2, and likewise has no position 4294967297. Every literal and prepared use of 4294967297 above should therefore fail with error 1054 instead of being interpreted as position 1. When 4294967296 is rejected, the diagnostic should identify the supplied value rather than column 0.

      Attachments

        Activity

          People

            psergei Sergei Petrunia
            imchifan 刘启帆
            Votes:
            0 Vote for this issue
            Watchers:
            3 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.