MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Jim Winstead Date:July 21 2006 8:28pm
Subject:bk commit into 5.0 tree (jimw:1.2207) BUG#16881
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of jimw. When jimw does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2006-07-21 13:28:42-07:00, jimw@rama.(none) +3 -0
  Bug #16881: password() and union select
  
    This was only demonstrated by the use of PASSWORD(), it was not related to
    that function at all. The calculation of the size of a field in the results
    of a UNION did not take into account the possible growth of a string field
    when being converted to the aggregated character set.

  mysql-test/r/union.result@stripped, 2006-07-21 13:28:38-07:00, jimw@rama.(none) +5 -0
    Add new results

  mysql-test/t/union.test@stripped, 2006-07-21 13:28:38-07:00, jimw@rama.(none) +7 -0
    Add new regression test

  sql/item.cc@stripped, 2006-07-21 13:28:38-07:00, jimw@rama.(none) +12 -4
    Fix calculation of max_length when figuring out the type of a column in
    a UNION. It needs to take into account any expansion of field size due to
    charset conversions.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	jimw
# Host:	rama.(none)
# Root:	/home/jimw/my/mysql-5.0-16881

--- 1.228/sql/item.cc	2006-07-21 13:28:46 -07:00
+++ 1.229/sql/item.cc	2006-07-21 13:28:46 -07:00
@@ -6053,14 +6053,13 @@ bool Item_type_holder::join_types(THD *t
     max_length= my_decimal_precision_to_length(precision, decimals,
                                                unsigned_flag);
   }
-  else
-    max_length= max(max_length, display_length(item));
- 
+
   switch (Field::result_merge_type(fld_type))
   {
   case STRING_RESULT:
   {
     const char *old_cs, *old_derivation;
+    uint32 old_max_chars= max_length / collation.collation->mbmaxlen;
     old_cs= collation.collation->name;
     old_derivation= collation.derivation_name();
     if (collation.aggregate(item->collation, MY_COLL_ALLOW_CONV))
@@ -6072,6 +6071,14 @@ bool Item_type_holder::join_types(THD *t
 	       "UNION");
       DBUG_RETURN(TRUE);
     }
+    /*
+      To figure out max_length, we have to take into account possible
+      expansion of the size of the values because of character set
+      conversions.
+     */
+    max_length= max(old_max_chars * collation.collation->mbmaxlen,
+                    display_length(item) / item->collation.collation->mbmaxlen *
+                    collation.collation->mbmaxlen);
     break;
   }
   case REAL_RESULT:
@@ -6090,7 +6097,8 @@ bool Item_type_holder::join_types(THD *t
       max_length= (fld_type == MYSQL_TYPE_FLOAT) ? FLT_DIG+6 : DBL_DIG+7;
     break;
   }
-  default:;
+  default:
+    max_length= max(max_length, display_length(item));
   };
   maybe_null|= item->maybe_null;
   get_full_info(item);

--- 1.82/mysql-test/r/union.result	2006-07-21 13:28:46 -07:00
+++ 1.83/mysql-test/r/union.result	2006-07-21 13:28:46 -07:00
@@ -1351,3 +1351,8 @@ drop table t1;
 (select avg(1)) union (select avg(1)) union (select avg(1));
 avg(1)
 NULL
+select _utf8'12' union select _latin1'12345';
+12
+12
+12345
+End of 5.0 tests

--- 1.95/mysql-test/t/union.test	2006-07-21 13:28:46 -07:00
+++ 1.96/mysql-test/t/union.test	2006-07-21 13:28:46 -07:00
@@ -841,3 +841,10 @@ drop table t1;
 (select avg(1)) union (select avg(1)) union (select avg(1)) union
 (select avg(1)) union (select avg(1)) union (select avg(1));
 
+#
+# Bug #16881: password() and union select
+# (The issue was poor handling of character set aggregation.)
+#
+select _utf8'12' union select _latin1'12345';
+
+--echo End of 5.0 tests
Thread
bk commit into 5.0 tree (jimw:1.2207) BUG#16881Jim Winstead21 Jul