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

Wrong result with combination of CONCAT,SUBSTR,SHA

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 10.0, 10.1, 10.2, 10.3
    • Fix Version/s: N/A
    • Component/s: OTHER
    • Labels:
      None

      Description

      This query erroneously returns NULL:

      SELECT UNHEX(CONCAT('414c2', HEX(8+ROUND(RAND()*7)),SUBSTR(SHA(''),6,7),HEX(2+ROUND(RAND())*8)));
      

      If I remove HEX, it correctly returns a string in hexadecimal format:

      SELECT CONCAT('414c2', HEX(8+ROUND(RAND()*7)),SUBSTR(SHA(''),6,7),HEX(2+ROUND(RAND())*8));
      

      +------------------------------------------------------------------------------------+
      | CONCAT('414c2', HEX(8+ROUND(RAND()*7)),SUBSTR(SHA(''),6,7),HEX(2+ROUND(RAND())*8)) |
      +------------------------------------------------------------------------------------+
      | 414c2B3ee5e6bA                                                                     |
      +------------------------------------------------------------------------------------+
      

      If I now add a user variable assignment, it erroneously returns a broken hexadecimal string:

      SELECT @a:=CONCAT('414c2', HEX(8+ROUND(RAND()*7)),SUBSTR(SHA(''),6,7),HEX(2+ROUND(RAND())*8));
      

      +----------------------------------------------------------------------------------------+
      | @a:=CONCAT('414c2', HEX(8+ROUND(RAND()*7)),SUBSTR(SHA(''),6,7),HEX(2+ROUND(RAND())*8)) |
      +----------------------------------------------------------------------------------------+
      | 414c299 ee56b2                                                                         |
      +----------------------------------------------------------------------------------------+
      

      The same problem is reproducible in a simplified query:

      SELECT @a:=CONCAT('2', '2', SUBSTR(SHA(''),6,7));
      

      +-------------------------------------------+
      | @a:=CONCAT('2', '2', SUBSTR(SHA(''),6,7)) |
      +-------------------------------------------+
      | 223ee5 6b                                 |
      +-------------------------------------------+
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bar Alexander Barkov
              Reporter:
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: