Bug #54483 valgrind errors when making warnings for multiline inserts into partition
Submitted: 14 Jun 2010 11:40 Modified: 26 Jan 2011 14:59
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Partitions Severity:S1 (Critical)
Version:5.1.47, 5.1.49-bzr OS:Any
Assigned to: Mattias Jonsson CPU Architecture:Any
Tags: valgrind

[14 Jun 2010 11:40] Shane Bester
Description:
Version: '5.1.47-enterprise-gpl-advanced'  socket: '/tmp/mysql.sock'  port: 3306  MySQL Enterprise Server - Advanced Edition (GPL)
Thread 11:
Conditional jump or move depends on uninitialised value(s)
at: strnlen 
by: my_vsnprintf 
by: my_snprintf_8bit 
by: make_truncated_value_warning
by: str_to_time_with_warn
by: Field::get_time
by: Item_field::get_time
by: Item_func_second::val_int
by: Item::get_date
by: Item_func_weekday::val_int
by: get_partition_id_list
by: get_part_id_charset_func_part
by: ha_partition::write_row
by: handler::ha_write_row
by: write_record
by: mysql_insert
by: mysql_execute_command
by: mysql_parse
by: dispatch_command
by: do_command
by: handle_one_connection
by: start_thread
by: clone

Then we notice corruption in the warnings returned:

 Truncated incorrect time value: 'test'
 Incorrect datetime value: '0'
 Truncated incorrect time value: 'aest'
 Incorrect datetime value: '0'
 Truncated incorrect time value: '5est'
 Incorrect datetime value: '5'

How to repeat:
#run mysqld under valgrind:

set sql_mode='';
drop table if exists t1;
create table t1(a varbinary(10))
partition by list (dayofweek(second(a)))
(partition a1 values in (1,null) engine = myisam);
insert into t1 values ('test'),('a'),('5');
[14 Jun 2010 11:43] MySQL Verification Team
the full valgrind output

Attachment: bug54483_5.1.47_full_valgrind_output.txt (text/plain), 26.57 KiB.

[14 Jun 2010 12:09] Valeriy Kravchuk
Verified just as described with recent 5.1.49 from bzr on Mac OS X. Note corrupted data in warnings:

valeriy-kravchuks-macbook-pro:5.1 openxs$ bin/mysql -uroot test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.49-debug Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set sql_mode='';
Query OK, 0 rows affected (0.01 sec)

mysql> drop table if exists t1;
Query OK, 0 rows affected (0.05 sec)

mysql> create table t1(a varbinary(10))
    -> partition by list (dayofweek(second(a)))
    -> (partition a1 values in (1,null) engine = myisam);
Query OK, 0 rows affected (0.28 sec)

mysql> insert into t1 values ('test'),('a'),('5');
Query OK, 3 rows affected, 6 warnings (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> show warnings\G
*************************** 1. row ***************************
  Level: Warning
   Code: 1292
Message: Truncated incorrect time value: 'test??????'
*************************** 2. row ***************************
  Level: Warning
   Code: 1292
Message: Incorrect datetime value: '0'
*************************** 3. row ***************************
  Level: Warning
   Code: 1292
Message: Truncated incorrect time value: 'aest??????'
*************************** 4. row ***************************
  Level: Warning
   Code: 1292
Message: Incorrect datetime value: '0'
*************************** 5. row ***************************
  Level: Warning
   Code: 1292
Message: Truncated incorrect time value: '5est??????'
*************************** 6. row ***************************
  Level: Warning
   Code: 1292
Message: Incorrect datetime value: '5'
6 rows in set (0.00 sec)
[19 Aug 2010 11:03] Mattias Jonsson
Problem is that second() and dayofweek accept a non DATE/DATETIME/TIME type in the partitioning function.
[20 Dec 2010 23:22] Mattias Jonsson
related to bug#57071. Time/date functions needs to have correct arguments to be allowed as partitioning functions.
[21 Dec 2010 9:35] MySQL Verification Team
look at bug #58180 also
[21 Dec 2010 23:38] Mattias Jonsson
kind of extending the fix for bug#42849.
[22 Dec 2010 9:51] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/127488

3530 Mattias Jonsson	2010-12-22
      Bug#54483: valgrind errors when making warnings for multiline inserts into partition
      Bug#57071: EXTRACT(WEEK from date_col) cannot be allowed as partitioning function
      
      There were functions allowed as partitioning functions
      that implicit allowed cast. That could result in unacceptable
      behaviour.
      
      Solution was to check that the arguments of date and time functions
      have allowed types (field and date/datetime/time depending on function).
     @ mysql-test/r/partition.result
        Updated result
     @ mysql-test/r/partition_error.result
        Updated result
     @ mysql-test/suite/parts/inc/part_supported_sql_funcs_main.inc
        disabled test with not allowed arguments.
     @ mysql-test/suite/parts/r/part_supported_sql_func_innodb.result
        Updated result
     @ mysql-test/suite/parts/r/part_supported_sql_func_myisam.result
        Updated result
     @ mysql-test/t/partition.test
        Fixed typo in bug number and removed non allowed function (bad argument)
     @ mysql-test/t/partition_error.test
        Added tests to verify correct type of argument.
     @ sql/item.h
        Renamed processor since it is no longer only for timezone
     @ sql/item_func.h
        Added help functions for checking date/time/datetime arguments.
     @ sql/item_timefunc.h
        Added processors for argument correctness
     @ sql/sql_partition.cc
        renamed the processor for checking arguments.
[22 Dec 2010 14:46] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/127510

3531 Mattias Jonsson	2010-12-22
      Bug#54483: valgrind errors when making warnings for
      multiline inserts into partition
      Bug#57071: EXTRACT(WEEK from date_col) cannot be
      allowed as partitioning function
      
      Renamed function according to reviewers comments.
     @ sql/item.h
        better name of processor function
     @ sql/item_func.h
        better name of processor function
     @ sql/item_timefunc.h
        better name of processor function
     @ sql/sql_partition.cc
        better name of processor function
        Updated comment.
[10 Jan 2011 16:49] Bugs System
Pushed into mysql-trunk 5.6.2 (revid:mattias.jonsson@oracle.com-20110110163747-ssccpoh0wesjl68q) (version source revid:mattias.jonsson@oracle.com-20110110163747-ssccpoh0wesjl68q) (merge vers: 5.6.2) (pib:24)
[10 Jan 2011 16:49] Bugs System
Pushed into mysql-5.5 5.5.9 (revid:mattias.jonsson@oracle.com-20110110160254-zodzbuutmr53468f) (version source revid:mattias.jonsson@oracle.com-20110110160254-zodzbuutmr53468f) (merge vers: 5.5.9) (pib:24)
[10 Jan 2011 16:50] Bugs System
Pushed into mysql-5.1 5.1.55 (revid:mattias.jonsson@oracle.com-20110110115627-2bj4218kve40go1r) (version source revid:mattias.jonsson@oracle.com-20110110115627-2bj4218kve40go1r) (merge vers: 5.1.55) (pib:24)
[10 Jan 2011 17:35] Mattias Jonsson
Note that this also fixes bug#57071, including disable EXTRACT(WEEK from ...) as partitioning function, since it depends on sql_mode. Closing that bug as a duplicate of this.
[26 Jan 2011 14:59] Jon Stephens
Documented bugfix/feature change in the 5.1.55, 5.5.9, and 5.6.2 changelogs, as follows:

        Date and time functions used as partitioning functions now have
        the types of their operands checked; use of a value of the wrong
        type is now disallowed in such cases. In addition, EXTRACT(WEEK
        FROM col), where col is a DATE or DATETIME column, is now
        disallowed altogether because its return value depends on the
        value of the default_week_format system variable.

Also updated tables/info about permitted/diallowed function in the Partitioning chanpter of the 5.1/5.5/5.6 versions of the Manual.

Closed.