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

MDEV-39661 fix introduces silent data corruption/NULL-correctness regression

    XMLWordPrintable

Details

    • Bug
    • Status: Approved (View Workflow)
    • Critical
    • Resolution: Unresolved
    • N/A
    • 13.1
    • None

    Description

      SELECT XXH32(CONCAT('a',NULL)) AS x32_must_be_null, XXH3(CONCAT('a',NULL)) AS x3_must_be_null;
      

      Leads to:

      MDEV-39661 CS 13.1.0 02e1853c894906737fe0ea5f836adb087b1a72ad (Debug, UBASAN, Clang 22.1.6-20260529) Build 15/06/2026

      13.1.0-dbg>  SELECT XXH32(CONCAT('a',NULL)) AS x32_must_be_null, XXH3(CONCAT('a',NULL)) AS x3_must_be_null;
      +------------------+-----------------+
      | x32_must_be_null | x3_must_be_null |
      +------------------+-----------------+
      |                0 |               0 |
      +------------------+-----------------+
      1 row in set (0.002 sec)
      

      Which is incorrect.

      AI Proposed fix:

      --- a/sql/item_strfunc.cc
      +++ b/sql/item_strfunc.cc
      @@ -4600,14 +4600,10 @@
       {
         DBUG_ASSERT(fixed());
         DBUG_ASSERT(arg_count == 1);
      -  if ((null_value= args[0]->null_value))
      -    return 0;
      -  else
      -  {
      -    Hasher hasher(my_hasher_xxh32());
      -    args[0]->hash_val_str(&hasher, &buffer);
      -    return static_cast<longlong>(hasher.finalize());
      -  }
      +  Hasher hasher(my_hasher_xxh32());
      +  args[0]->hash_val_str(&hasher, &buffer);
      +  ulonglong h= hasher.finalize();
      +  return (null_value= args[0]->null_value) ? 0 : static_cast<longlong>(h);
       }
       
       bool Item_func_xxh3::check_arguments() const
      @@ -4619,15 +4615,10 @@
       {
         DBUG_ASSERT(fixed());
         DBUG_ASSERT(arg_count == 1);
      -
      -  if ((null_value= args[0]->null_value))
      -    return 0;
      -  else
      -  {
      -    Hasher hasher(my_hasher_xxh3());
      -    args[0]->hash_val_str(&hasher, &buffer);
      -    return static_cast<longlong>(hasher.finalize());
      -  }
      +  Hasher hasher(my_hasher_xxh3());
      +  args[0]->hash_val_str(&hasher, &buffer);
      +  ulonglong h= hasher.finalize();
      +  return (null_value= args[0]->null_value) ? 0 : static_cast<longlong>(h);
       }
       
       #ifdef HAVE_COMPRESS
      

      With the fix applied on top of the PR we get:

      MDEV-39661 CS 13.1.0 02e1853c894906737fe0ea5f836adb087b1a72ad+fix (Debug, UBASAN, Clang 22.1.6-20260529) Build 15/06/2026

      13.1.0-dbg>SELECT XXH32(CONCAT('a',NULL)) AS x32_must_be_null, XXH3(CONCAT('a',NULL)) AS x3_must_be_null;
      +------------------+-----------------+
      | x32_must_be_null | x3_must_be_null |
      +------------------+-----------------+
      |             NULL |            NULL |
      +------------------+-----------------+
      1 row in set (0.002 sec)
      

      The fix may require further review.

      Attachments

        Issue Links

          Activity

            People

              danblack Daniel Black
              Roel Roel Van de Paar
              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.