Bug #59345 libmysqlclient_r.so crashed in my_read when mysql_query("LOAD DATA LOCAL")
Submitted: 7 Jan 2011 9:40 Modified: 8 Dec 2014 11:49
Reporter: Jian Huang Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / C Severity:S2 (Serious)
Version:6.0.2 OS:Linux (SUSE 10 x86 )
Assigned to: CPU Architecture:Any
Tags: crash, load, local, my_read, mysql_query

[7 Jan 2011 9:40] Jian Huang
Description:
I need to use mysql_query("LOAD DATA LOCAL") to load data to remote database. The data is in the below format:
460022103337063 8615210477725
460028105330734 8615810562353
460029105304332 8615910524332
460000673116331 8613810680510
460028101119989 8615810147535
460022307022453 8615230745604
460001040216726 8613521326068
460028015918946 8615801452690
460020390010916 8613439060399

But unfortunately, there is always coredump when loading from the file.
The client library is mysql-connector-c-6.0.2-linux-sles10-x86.tar.gz which is the latest version from dev.mysql.com/download. We will use libmysql.so.16.0.0.
My codes are as below:
    m_pMySQL = mysql_init(NULL);
    if(!m_pMySQL)
    {
        A7C_LOG_ERROR (logCat, "Can not init mysql!");
        return STATUS_ERROR;
    }
    if(0 != mysql_options(m_pMySQL, MYSQL_OPT_LOCAL_INFILE, 0))
    {
        A7C_LOG_ERROR (logCat, "Can not set mysql to local infile !");
    }

    if(!mysql_real_connect(m_pMySQL,
        m_host.c_str(),
        m_username.c_str(),
        m_password.c_str(),
        m_dbname.c_str(),
        m_port,
        NULL,
        //0))
        CLIENT_MULTI_RESULTS|CLIENT_LOCAL_FILES))
    {
        A7C_LOG_ERROR (logCat, "Can not connect mysql server. ERROR: "<<mysql_error(m_pMySQL));
        return STATUS_ERROR;
    }

    string load("LOAD DATA LOCAL INFILE '/var/tmp/TDR_HTU1_TID01' IGNORE INTO TABLE LOOKUP");
    if(mysql_query(m_pMySQL, load.c_str()))
        {
        A7C_LOG_ERROR (logCat, "Failed to load. Statement: "
            <<load<<". Error:"<<mysql_error(m_pMySQL));
        return STATUS_ERROR;
        }

Core info by gdb:

Program terminated with signal 11, Segmentation fault.
#0  0xf7b362d1 in my_read (Filedes=18,
    Buffer=0xf3645a40 "460001191124402\t8613611226646\n460027014803029\t8618701483175\n460028101539830\t8615810184408\n460020264337590\t8613426218170\n460022102200877\t8615210220922\n460023100016582\t8615010067740\n460021537608606\t8615"..., Count=8192, MyFlags=<value optimized out>) at /export/home2/tmp/cteam/bs/connector-c/src/mysql-connector-c-6.0.2/mysys/my_read.c:55
55      /export/home2/tmp/cteam/bs/connector-c/src/mysql-connector-c-6.0.2/mysys/my_read.c: No such file or directory.
        in /export/home2/tmp/cteam/bs/connector-c/src/mysql-connector-c-6.0.2/mysys/my_read.c
(gdb) where
#0  0xf7b362d1 in my_read (Filedes=18,
    Buffer=0xf3645a40 "460001191124402\t8613611226646\n460027014803029\t8618701483175\n460028101539830\t8615810184408\n460020264337590\t8613426218170\n460022102200877\t8615210220922\n460023100016582\t8615010067740\n460021537608606\t8615"..., Count=8192, MyFlags=<value optimized out>) at /export/home2/tmp/cteam/bs/connector-c/src/mysql-connector-c-6.0.2/mysys/my_read.c:55
#1  0xf7ac513d in default_local_infile_read (ptr=0xf3d59190,
    buf=0xf3645a40 "460001191124402\t8613611226646\n460027014803029\t8618701483175\n460028101539830\t8615810184408\n460020264337590\t8613426218170\n460022102200877\t8615210220922\n460023100016582\t8615010067740\n460021537608606\t8615"..., buf_len=8192) at /export/home2/tmp/cteam/bs/connector-c/src/mysql-connector-c-6.0.2/libmysql/libmysql.c:693
#2  0xf7ac5337 in handle_local_infile (mysql=0x80aa6c0, net_filename=0x80add11 "/var/tmp/TDR_HTU1_TID01") at /export/home2/tmp/cteam/bs/connector-c/src/mysql-connector-c-6.0.2/libmysql/libmysql.c:577
#3  0xf7ac0532 in cli_read_query_result (mysql=0x80aa6c0) at /export/home2/tmp/cteam/bs/connector-c/src/mysql-connector-c-6.0.2/libmysql/client.c:2867
#4  0xf7abcc04 in mysql_real_query (mysql=0x80aa6c0, query=0x807c2d4 "LOAD DATA LOCAL INFILE '/var/tmp/TDR_HTU1_TID01' IGNORE INTO TABLE LOOKUP", length=73)
    at /export/home2/tmp/cteam/bs/connector-c/src/mysql-connector-c-6.0.2/libmysql/client.c:2912
#5  0xf7ac4f75 in mysql_query (mysql=0x80aa6c0, query=0x807c2d4 "LOAD DATA LOCAL INFILE '/var/tmp/TDR_HTU1_TID01' IGNORE INTO TABLE LOOKUP")
    at /export/home2/tmp/cteam/bs/connector-c/src/mysql-connector-c-6.0.2/libmysql/libmysql.c:790

If I change to use command line client of mysql, it works well.
This has blocked our project. Please help!

How to repeat:
460001191124402 8613611226646
460027014803029 8618701483175
460028101539830 8615810184408
460020264337590 8613426218170
460022102200877 8615210220922
460023100016582 8615010067740
460021537608606 8615163782668
460000403128623 8613810409078
460020368735130 8613436972415
460001279011155 8613901011230
460022014333013 8615201467356
460000283117822 8613811447922
460022102402438 8615210242566
460020010410952 8613401128116
460029343827214 8613834788609
460001054138280 8613910936975
460001441905049 8613691445049
460020010232888 8613401095441
460021100908362 8615110098761
460004800246220 8613524864741
460000794129782 8613910762794
460021169239220 8615116968354
460001543115611 8613811373908
460001181707309 8613671187309
460001553116285 8613811548437
460000394103538 8613910453538
460028010636950 8615801008279
460020749963455 8613474994301
460023012907256 8615001297607
460000314129497 8613910396395
460001570219307 8613521478666
460000260232649 8613520240399
460020665631201 8613466534476
460021649676085 8615148528884
460001293104340 8613811294340
460079013408758 8614701349188
460029015117834 8615901537572
460003181834151 8613683085317
460029011109001 8615901119001
460027093429536 8618793439298
460020887204798 8613488724798
460023110203742 8615011023927
460023109906467 8615010996793
460001054428308 8613941001106
460001085029666 8613501035652
460000313125009 8613811952056
460003111811472 8613683114339
460000880223194 8613520955221
460020394019018 8613439806353
460028104114535 8615810405037
460001155029840 8613501211380

Use the above as contents of file, then load by mysql_query("LOAD DATA LOCAL"), the issue will always happen.
[30 Mar 2011 17:54] Valeriy Kravchuk
Please, send the output of:

show create table LOOKUP\G

What server version, x.y.z, did you use?
[2 Apr 2011 9:44] Jian Huang
mysql> show create table LOOKUP;
+--------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table  | Create Table                                                                                                                                                                                                                                                                                                        |
+--------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| LOOKUP | CREATE TABLE `LOOKUP` (
  `imsi` varchar(15) COLLATE ascii_bin NOT NULL,
  `msisdn` varchar(26) COLLATE ascii_bin NOT NULL,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`imsi`,`msisdn`),
  KEY `LOOKUP_IDX` (`imsi`,`msisdn`)
) ENGINE=MyISAM DEFAULT CHARSET=ascii COLLATE=ascii_bin |
+--------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

The version of mysql is 5.1.41
[10 May 2012 18:04] Sveta Smirnova
Thank you for the report.

I can not repeat described behavior. Do you experience same problem if use LOAD DATA INFILE (not LOCAL)? Could you please provide full example of C code you use?
[11 Jun 2012 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[7 Nov 2014 14:54] Yashwanth M
I'm facing the same problem with one of my application. That too in LOAD DATA LOCAL INFILE only. But the same application is running fine in another server with out any Difference in Configurations. Why is this like this?
[5 Dec 2014 17:49] Sveta Smirnova
Yashwanth,

could you please provide example of C code which fails? Thanks in advance.
[8 Dec 2014 6:20] Yashwanth M
I got it fixed. It was problem with mysqlpp C++ Wrapper i think. In the server where I was getting this kind of error had mysqlpp3.1.0, which caused problem. I reverted that with mysqlpp3.0. Now it's fine. Thank you.
[8 Dec 2014 11:49] Sveta Smirnova
Thank you for the feedback.

Closed as "Not a Bug" since the reason of wrong behavior was not MySQL code.
[8 May 2018 9:58] Sarath T
I have got the same error in my code  

0x00eed626 in my_read (Filedes=8, 
    Buffer=0xf1012478 "26&&==80000004&&==0&&==8265&&==internal&&==555343454C00010131363630363736383332380001013136363036373631343935", '0' <repeats 17 times>, "300023F21020400020018&&==176971895==##==26&&==80000004&&==0&&==8268&&==int"..., Count=8192, MyFlags=0) at /export/home/pb2/build/sb_0-9099207-1367226740.47/rpm/BUILD/mysql-5.6.11/mysql-5.6.11/mysys/my_read.c:55
#1  0x00eb9edc in default_local_infile_read (ptr=0xf101a908, 
    buf=0xf1012478 "26&&==80000004&&==0&&==8265&&==internal&&==555343454C00010131363630363736383332380001013136363036373631343935", '0' <repeats 17 times>, "300023F21020400020018&&==176971895==##==26&&==80000004&&==0&&==8268&&==int"..., buf_len=8192) at /export/home/pb2/build/sb_0-9099207-1367226740.47/rpm/BUILD/mysql-5.6.11/mysql-5.6.11/libmysql/libmysql.c:602
#2  0x00eba172 in handle_local_infile (mysql=0xf100918c, net_filename=0xf100fe69 "./cdr/processor/D1SUBMIT_2018_04_28_22_03_44_93_1.TXT")
    at /export/home/pb2/build/sb_0-9099207-1367226740.47/rpm/BUILD/mysql-5.6.11/mysql-5.6.11/libmysql/libmysql.c:485
#3  0x00ebe981 in cli_read_query_result (mysql=0xf100918c) at /export/home/pb2/build/sb_0-9099207-1367226740.47/rpm/BUILD/mysql-5.6.11/mysql-5.6.11/sql-common/client.c:4057
#4  0x00ebb3e7 in mysql_real_query (mysql=0xf100918c, 
    query=0xf101a808 "load data local infile './cdr/processor/D1SUBMIT_2018_04_28_22_03_44_93_1.TXT' into table SUBMIT fields terminated by '&&==' lines terminated by '==##==' (Command_Length,Command_Id,Command_Status,Sequ"..., length=230) at /export/home/pb2/build/sb_0-9099207-1367226740.47/rpm/BUILD/mysql-5.6.11/mysql-5.6.11/sql-common/client.c:4103
#5  0x00ae25ea in execute (this=0xf2ffee40, 
    str=0xf101a808 "load data local infile './cdr/processor/D1SUBMIT_2018_04_28_22_03_44_93_1.TXT' into table SUBMIT fields terminated by '&&==' lines terminated by '==##==' (Command_Length,Command_Id,Command_Status,Sequ"..., len=230) at ./lib/dbdriver.h:288
#6  mysqlpp::Query::execute (this=0xf2ffee40, 
    str=0xf101a808 "load data local infile './cdr/processor/D1SUBMIT_2018_04_28_22_03_44_93_1.TXT' into table SUBMIT fields terminated by '&&==' lines terminated by '==##==' (Command_Length,Command_Id,Command_Status,Sequ"..., len=230) at ./lib/query.cpp:206
#7  0x00ae289d in mysqlpp::Query::execute (this=0xf2ffee40, s=...) at ./lib/query.cpp:190
#8  0x00ae293d in mysqlpp::Query::execute (this=0xf2ffee40) at ./lib/query.cpp:165
#9  0x08054338 in CDBDetails::mcfn_LoadDB (this=0xf6c0a360, pscL_TableName=0xf2fff1c0 "SUBMIT", pscL_Path=...) at DBDetails.cpp:68
#10 0x0805affc in CFileUploader::mcfn_processFiles (this=0xf6c09ad8) at FileUploader.cpp:347
#11 0x080585ef in mcfnS_processThread (pvL_This=0xf6c09ad8) at FileUploader.cpp:17
#12 0x00718a49 in start_thread () from /lib/libpthread.so.0
#13 0x0045ae1e in clone () from /lib/libc.so.6