Bug #58371 Assertion failed: !s.uses_buffer_owned_by(this) with format string function
Submitted: 22 Nov 2010 7:18 Modified: 29 Jan 2011 23:08
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Charsets Severity:S1 (Critical)
Version:5.1.53-debug, 5.5.8-debug, 5.6.1-debug OS:Any
Assigned to: Alexander Barkov CPU Architecture:Any
Tags: assertion, format
Triage: Triaged: D1 (Critical)

[22 Nov 2010 7:18] Shane Bester
Description:
Version: '5.5.7-rc-debug'  socket: ''  port: 3306  MySQL Community Server - Debug (GPL)
Assertion failed: !s.uses_buffer_owned_by(this), file g:\pb2\build\sb_0-2482024-1288735657.52\mysql-5.5.7-rc\sql\sql_string.h, line 247

mysqld-debug.exe!my_sigabrt_handler()[my_thr_init.c:521]
mysqld-debug.exe!raise()[winsig.c:590]
mysqld-debug.exe!abort()[abort.c:71]
mysqld-debug.exe!_wassert()[assert.c:163]
mysqld-debug.exe!String::operator=()[sql_string.h:247]
mysqld-debug.exe!Item_char_typecast::val_str()[item_timefunc.cc:2558]
mysqld-debug.exe!Item_func_conv_charset::val_str()[item_strfunc.cc:2919]
mysqld-debug.exe!Item_str_func::val_int()[item_strfunc.cc:161]
mysqld-debug.exe!mysql_do()[sql_do.cc:34]
mysqld-debug.exe!mysql_execute_command()[sql_parse.cc:2088]
mysqld-debug.exe!mysql_parse()[sql_parse.cc:5499]
mysqld-debug.exe!dispatch_command()[sql_parse.cc:1029]
mysqld-debug.exe!do_command()[sql_parse.cc:769]
mysqld-debug.exe!do_handle_one_connection()[sql_connect.cc:745]
mysqld-debug.exe!handle_one_connection()[sql_connect.cc:684]
mysqld-debug.exe!pthread_start()[my_winthread.c:61]
mysqld-debug.exe!_callthreadstartex()[threadex.c:348]
mysqld-debug.exe!_threadstartex()[threadex.c:331]

How to repeat:
on debug build:

do convert(cast(substring_index(format(1,'1111','nb_NO'),
format('','Zpq','ms_MY'),1) as binary(0)) using hp8);
[22 Nov 2010 8:03] Valeriy Kravchuk
There is no crash on 5.1.54, so this looks like a regression:

openxs@ubuntu:~/dbs/5.5-sec$ bin/mysql --no-defaults -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.54-valgrind-max-debug Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> do convert(cast(substring_index(format(1,'1111','nb_NO'),
    -> format('','Zpq','ms_MY'),1) as binary(0)) using hp8);
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'format'
[22 Nov 2010 8:06] Valeriy Kravchuk
Verified with current mysql-trunk on 32-bit Ubuntu:

Version: '5.6.1-m5-debug'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
mysqld: sql_string.h:253: String& String::operator=(const String&): Assertion `!s.uses_buffer_owned_by(this)' failed.
101122 10:04:54 - mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.

key_buffer_size=8388608
read_buffer_size=131072
max_used_connections=1
max_threads=151
thread_count=1
connection_count=1
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 337976 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd: 0xa88b0c0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0xa92b335c thread_stack 0x30000
/home/openxs/dbs/trunk/libexec/mysqld(my_print_stacktrace+0x33)[0x862b25e]
/home/openxs/dbs/trunk/libexec/mysqld(handle_segfault+0x2c1)[0x8285e38]
[0xc81400]
/lib/tls/i686/cmov/libc.so.6(abort+0x182)[0x50ca82]
/lib/tls/i686/cmov/libc.so.6(__assert_fail+0xf8)[0x502718]
/home/openxs/dbs/trunk/libexec/mysqld(_ZN6StringaSERKS_+0x48)[0x8202a4c]
/home/openxs/dbs/trunk/libexec/mysqld(_ZN18Item_char_typecast7val_strEP6String+0x28f)[0x821c62d]
/home/openxs/dbs/trunk/libexec/mysqld(_ZN22Item_func_conv_charset7val_strEP6String+0x8b)[0x82102a1]
/home/openxs/dbs/trunk/libexec/mysqld(_ZN13Item_str_func7val_intEv+0x84)[0x82072e8]
/home/openxs/dbs/trunk/libexec/mysqld(_Z8mysql_doP3THDR4ListI4ItemE+0xa0)[0x836a444]
/home/openxs/dbs/trunk/libexec/mysqld(_Z21mysql_execute_commandP3THD+0xab1)[0x8296839]
/home/openxs/dbs/trunk/libexec/mysqld(_Z11mysql_parseP3THDPcjP12Parser_state+0x1d6)[0x82a0056]
/home/openxs/dbs/trunk/libexec/mysqld(_Z16dispatch_command19enum_server_commandP3THDPcj+0x760)[0x82941e9]
/home/openxs/dbs/trunk/libexec/mysqld(_Z10do_commandP3THD+0x242)[0x829388c]
/home/openxs/dbs/trunk/libexec/mysqld(_Z24do_handle_one_connectionP3THD+0x199)[0x8291bee]
/home/openxs/dbs/trunk/libexec/mysqld(handle_one_connection+0x28)[0x8291a4e]
/lib/tls/i686/cmov/libpthread.so.0(+0x596e)[0x81d96e]
/lib/tls/i686/cmov/libc.so.6(clone+0x5e)[0x5aca4e]
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at 0xa9099d0 = do convert(cast(substring_index(format(1,'1111','nb_NO'),
format('','Zpq','ms_MY'),1) as binary(0)) using hp8)
thd->thread_id=1
thd->killed=NOT_KILLED
...
[22 Nov 2010 8:22] Shane Bester
5.1.53 is also affected with this testcase:

do convert(cast(substring_index(format(1,'1111'),format('','Zpq'),1) as binary(0)) using hp8);

Version: '5.1.53-enterprise-gpl-advanced-debug'  socket: ''  port: 3306  MySQL Enterprise Server - Advanced Edition Debug (GPL)
Assertion failed: !s.uses_buffer_owned_by(this), file g:\mysql-5.1.53-winbuild\mysql-advanced-gpl-debug-5.1.53-build\sql\sql_string.h, line 239
mysqld-debug.exe!my_sigabrt_handler()[mysqld.cc:2086]
mysqld-debug.exe!raise()[winsig.c:597]
mysqld-debug.exe!abort()[abort.c:78]
mysqld-debug.exe!_wassert()[assert.c:212]
mysqld-debug.exe!String::operator=()[sql_string.h:239]
mysqld-debug.exe!Item_char_typecast::val_str()[item_timefunc.cc:2488]
mysqld-debug.exe!Item_func_conv_charset::val_str()[item_strfunc.cc:2763]
mysqld-debug.exe!Item_str_func::val_int()[item_strfunc.cc:107]
mysqld-debug.exe!mysql_do()[sql_do.cc:29]
mysqld-debug.exe!mysql_execute_command()[sql_parse.cc:2315]
mysqld-debug.exe!mysql_parse()[sql_parse.cc:6072]
mysqld-debug.exe!dispatch_command()[sql_parse.cc:1263]
mysqld-debug.exe!do_command()[sql_parse.cc:889]
mysqld-debug.exe!handle_one_connection()[sql_connect.cc:1136]
mysqld-debug.exe!pthread_start()[my_winthread.c:85]
mysqld-debug.exe!_callthreadstart()[thread.c:295]
mysqld-debug.exe!_threadstart()[thread.c:277]
kernel32.dll!BaseThreadStart()
[14 Jan 2011 13:44] Alexander Barkov
The same crash happens with utf8:

do convert(cast(substring_index(format(1,'1111'), format('','Zpq'),1) as binary(0)) using utf8);
[14 Jan 2011 17:00] 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/128826

3553 Alexander Barkov	2011-01-14
      Bug#58371 Assertion failed: !s.uses_buffer_owned_by(this) with format string function
      
      Introduced by the fix for bug#44766.
      
      Problem: it's not correct to use args[0]->str_value as a buffer,
      because args[0] may need this buffer for its own purposes.
      
      Fix: adding a new class member tmp_value to use as return value.
      
        @ mysql-test/r/ctype_many.result
        @ mysql-test/t/ctype_many.test
        Adding tests
      
        @ sql/item_strfunc.cc
        Changing code into traditional style:
        use "str" as a buffer for the argument and tmp_value for the result value.
      
        @ sql/item_strfunc.h
        Adding tmp_value
[17 Jan 2011 12:15] 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/128945

3557 Alexander Barkov	2011-01-17
      Bug#58371 Assertion failed: !s.uses_buffer_owned_by(this) with format string function
      
      Introduced by the fix for bug#44766.
      
      Problem: it's not correct to use args[0]->str_value as a buffer,
      because args[0] may need this buffer for its own purposes.
      
      Fix: adding a new class member tmp_value to use as return value.
      
        @ mysql-test/r/ctype_many.result
        @ mysql-test/t/ctype_many.test
        Adding tests
      
        @ sql/item_strfunc.cc
        Changing code into traditional style:
        use "str" as a buffer for the argument and tmp_value for the result value.
      
        @ sql/item_strfunc.h
        Adding tmp_value
[17 Jan 2011 12:15] Bugs System
Pushed into mysql-5.1 5.1.56 (revid:alexander.barkov@oracle.com-20110117121133-64dwqa4aiu382e7y) (version source revid:alexander.barkov@oracle.com-20110117121133-64dwqa4aiu382e7y) (merge vers: 5.1.56) (pib:24)
[17 Jan 2011 12:31] Bugs System
Pushed into mysql-5.5 5.5.10 (revid:alexander.barkov@oracle.com-20110117122613-tlwbdj268iau16rk) (version source revid:alexander.barkov@oracle.com-20110117122613-tlwbdj268iau16rk) (merge vers: 5.5.10) (pib:24)
[17 Jan 2011 12:39] Bugs System
Pushed into mysql-trunk 5.6.2 (revid:alexander.barkov@oracle.com-20110117123558-9z1ce4fbkrt9a7bi) (version source revid:alexander.barkov@oracle.com-20110117123558-9z1ce4fbkrt9a7bi) (merge vers: 5.6.2) (pib:24)
[20 Jan 2011 19:42] Paul Dubois
Noted in 5.1.56, 5.5.10, 5.6.2 changelogs.

In debug builds, SUBSTRING_INDEX(FORMAT(...), FORMAT(...)) could
cause a server crash.