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

COMPRESS of a 1 GB string stores the length as 0, so UNCOMPRESS gives NULL

    XMLWordPrintable

Details

    Description

      Likely cause: old code in Item_func_compress::val_str() from 2003, not a recent change. MySQL 5.5 to 9.1 give the same result.

      SET @save_max_allowed_packet= @@global.max_allowed_packet;
      SET GLOBAL max_allowed_packet= 1073741824;
      --connect (con1,localhost,root)
      SET @c= COMPRESS(REPEAT('a',1073741824));
      --let $l= query_get_value(SELECT LENGTH(UNCOMPRESS(@c)) AS l, l, 1)
      if ($l != 1073741824)
      {
        --die UNCOMPRESS did not give back the 1073741824 byte string that COMPRESS was given, the result length is $l
      }
      --disconnect con1
      --connection default
      SET GLOBAL max_allowed_packet= @save_max_allowed_packet;

      Leads to:

      CS 13.1.2 87e62ca17270e163a6d41b3fc8d6f4d440f1bb88 (Optimized, Clang 22.1.8-20260622) Build 05/10/2026

      mysqltest: At line 8: UNCOMPRESS did not give back the 1073741824 byte string that COMPRESS was given, the result length is NULL

      In the client, with max_allowed_packet at 1073741824:

      CS 13.1.2 87e62ca17270e163a6d41b3fc8d6f4d440f1bb88 (Optimized, Clang 22.1.8-20260622) Build 05/10/2026

      SELECT UNCOMPRESSED_LENGTH(COMPRESS(REPEAT('a',1073741823))) AS at_1073741823;
      at_1073741823
      1073741823
       
      SELECT UNCOMPRESSED_LENGTH(COMPRESS(REPEAT('a',1073741824))) AS at_1073741824;
      at_1073741824
      0
       
      SELECT LENGTH(UNCOMPRESS(COMPRESS(REPEAT('a',1073741824)))) AS uncompress_len;
      uncompress_len
      NULL
       
      SHOW WARNINGS;
      Level	Code	Message
      Warning	1258	ZLIB: Not enough room in the output buffer (probably, length of uncompressed data was corrupted)

      COMPRESS() itself gives no warning. With one byte less, UNCOMPRESS() gives the string back.

      From the code it seems that Item_func_compress::val_str() writes the source length into the first four bytes masked with 0x3FFFFFFF, so 1073741824 is stored as 0. Item_func_uncompressed_length::val_int() reads it back with the same mask, and Item_func_uncompress::val_str() uses it as the size of the output buffer.

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              Roel Roel Van de Paar
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - Not Specified
                  Not Specified
                  Logged:
                  Time Spent - 20m
                  20m

                  Git Integration

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