Bug #81411 Assertion `n_linear_rings > 0' failed. in Gis_polygon::centroid_xy
Submitted: 13 May 2016 4:18 Modified: 16 Nov 2017 7:46
Reporter: Roel Van de Paar Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: GIS Severity:S6 (Debug Builds)
Version:5.5.49 OS:Any
Assigned to: CPU Architecture:Any

[13 May 2016 4:18] Roel Van de Paar
Description:
mysqld: /git/mysql-server/sql/spatial.cc:959: int Gis_polygon::centroid_xy(double*, double*) const: Assertion `n_linear_rings > 0' failed.
04:02:32 UTC - mysqld got signal 6 ;

+bt
#0  0x00007f909eb7c741 in __pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ../nptl/sysdeps/unix/sysv/linux/pthread_kill.c:61
#1  0x00000000007de0c8 in my_write_core (sig=6) at /git/mysql-server/mysys/stacktrace.c:433
#2  0x00000000006a1088 in handle_fatal_signal (sig=6) at /git/mysql-server/sql/signal_handler.cc:247
#3  <signal handler called>
#4  0x00007f909db9d5f7 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#5  0x00007f909db9ece8 in __GI_abort () at abort.c:90
#6  0x00007f909db96566 in __assert_fail_base (fmt=0x7f909dce6228 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0xb1b259 "n_linear_rings > 0", file=file@entry=0xb1b2a0 "/git/mysql-server/sql/spatial.cc", line=line@entry=959, function=function@entry=0xb1b2e0 <Gis_polygon::centroid_xy(double*, double*) const::__PRETTY_FUNCTION__> "int Gis_polygon::centroid_xy(double*, double*) const") at assert.c:92
#7  0x00007f909db96612 in __GI___assert_fail (assertion=0xb1b259 "n_linear_rings > 0", file=0xb1b2a0 "/git/mysql-server/sql/spatial.cc", line=959, function=0xb1b2e0 <Gis_polygon::centroid_xy(double*, double*) const::__PRETTY_FUNCTION__> "int Gis_polygon::centroid_xy(double*, double*) const") at assert.c:101
#8  0x000000000078d3db in Gis_polygon::centroid_xy (this=this@entry=0x7f909f18bcf0, x=x@entry=0x7f909f18bcc0, y=y@entry=0x7f909f18bcc8) at /git/mysql-server/sql/spatial.cc:959
#9  0x000000000078d62c in Gis_polygon::centroid (this=0x7f909f18bcf0, result=0x7f909f18bdd0) at /git/mysql-server/sql/spatial.cc:1017
#10 0x00000000006fe87c in Item_func_centroid::val_str (this=0x7f9003c3a918, str=0x7f909f18bdd0) at /git/mysql-server/sql/item_geofunc.cc:243
#11 0x00000000006ad8d5 in Item::send (this=0x7f9003c3a918, protocol=0x7f9012b204a8, buffer=0x7f909f18bdd0) at /git/mysql-server/sql/item.cc:5997
#12 0x0000000000513aae in Protocol::send_result_set_row (this=this@entry=0x7f9012b204a8, row_items=row_items@entry=0x7f9012b22188) at /git/mysql-server/sql/protocol.cc:847
#13 0x000000000055b054 in select_send::send_data (this=0x7f9003c3aaa0, items=...) at /git/mysql-server/sql/sql_class.cc:2240
#14 0x00000000005d068b in JOIN::exec (this=this@entry=0x7f9003c26010) at /git/mysql-server/sql/sql_select.cc:1894
#15 0x00000000005cc82d in mysql_select (thd=thd@entry=0x7f9012b20000, rref_pointer_array=rref_pointer_array@entry=0x7f9012b22260, tables=0x0, wild_num=0, fields=..., conds=<optimized out>, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=select_options@entry=2147748608, result=result@entry=0x7f9003c3aaa0, unit=unit@entry=0x7f9012b21a58, select_lex=select_lex@entry=0x7f9012b22078) at /git/mysql-server/sql/sql_select.cc:2619
#16 0x00000000005cca25 in handle_select (thd=thd@entry=0x7f9012b20000, lex=lex@entry=0x7f9012b219a8, result=result@entry=0x7f9003c3aaa0, setup_tables_done_option=setup_tables_done_option@entry=0) at /git/mysql-server/sql/sql_select.cc:297
#17 0x0000000000583b27 in execute_sqlcom_select (thd=thd@entry=0x7f9012b20000, all_tables=<optimized out>) at /git/mysql-server/sql/sql_parse.cc:4625
#18 0x00000000005899c6 in mysql_execute_command (thd=thd@entry=0x7f9012b20000) at /git/mysql-server/sql/sql_parse.cc:2176
#19 0x0000000000590ff6 in mysql_parse (thd=thd@entry=0x7f9012b20000, rawbuf=<optimized out>, length=71, parser_state=parser_state@entry=0x7f909f18d680) at /git/mysql-server/sql/sql_parse.cc:5780
#20 0x0000000000592843 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x7f9012b20000, packet=packet@entry=0x7f9012b12781 "", packet_length=packet_length@entry=71) at /git/mysql-server/sql/sql_parse.cc:1038
#21 0x00000000005946cc in do_command (thd=0x7f9012b20000) at /git/mysql-server/sql/sql_parse.cc:773
#22 0x000000000063c978 in do_handle_one_connection (thd_arg=thd_arg@entry=0x7f9012b20000) at /git/mysql-server/sql/sql_connect.cc:862
#23 0x000000000063ca35 in handle_one_connection (arg=0x7f9012b20000) at /git/mysql-server/sql/sql_connect.cc:781
#24 0x00007f909eb77dc5 in start_thread (arg=0x7f909f18e700) at pthread_create.c:308
#25 0x00007f909dc5e21d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:113

How to repeat:
SELECT Centroid(AsBinary(LineString(Point(0,0),Point(0,0),Point(0,0))));
[13 May 2016 6:59] MySQL Verification Team
Hello Roel,

Thank you for the report and test case.
Observed that 5.5.49(also, 5.5.51 daily build) debug build is
affected.

Thanks,
Umesh
[13 May 2016 6:59] MySQL Verification Team
-- 5.5.49 - 

rm -rf 81407
scripts/mysql_install_db --basedir=/export/umesh/server/binaries/mysql-advanced-5.5.49 --datadir=/export/umesh/server/binaries/mysql-advanced-5.5.49/81407
bin/mysqld-debug --basedir=/export/umesh/server/binaries/mysql-advanced-5.5.49 --datadir=/export/umesh/server/binaries/mysql-advanced-5.5.49/81407 --core-file --socket=/tmp/mysql_ushastry.sock  --port=15000 --log-error=/export/umesh/server/binaries/mysql-advanced-5.5.49/81407/log.err 2>&1 &

-- only debug build affected

(gdb) bt
#0  0x00007f3b599c2771 in pthread_kill () from /lib64/libpthread.so.0
#1  0x00000000007ee286 in my_write_core (sig=6) at /pb2/build/sb_0-18115917-1456812692.68/mysqlcom-pro-5.5.49/mysys/stacktrace.c:433
#2  0x00000000006a61fc in handle_fatal_signal (sig=6) at /pb2/build/sb_0-18115917-1456812692.68/mysqlcom-pro-5.5.49/sql/signal_handler.cc:247
#3  <signal handler called>
#4  0x00007f3b58ae55d7 in raise () from /lib64/libc.so.6
#5  0x00007f3b58ae6cc8 in abort () from /lib64/libc.so.6
#6  0x00007f3b58ade546 in __assert_fail_base () from /lib64/libc.so.6
#7  0x00007f3b58ade5f2 in __assert_fail () from /lib64/libc.so.6
#8  0x000000000079a0ee in Gis_polygon::centroid_xy (this=0x7f3b54086c20, x=0x7f3b54086bd8, y=0x7f3b54086bd0) at /pb2/build/sb_0-18115917-1456812692.68/mysqlcom-pro-5.5.49/sql/spatial.cc:959
#9  0x000000000079c68d in Gis_polygon::centroid (this=0x1ce6, result=0x7f3b54086ff0) at /pb2/build/sb_0-18115917-1456812692.68/mysqlcom-pro-5.5.49/sql/spatial.cc:1017
#10 0x0000000000706353 in Item_func_centroid::val_str (this=0x7f3b3c0054d0, str=0x7f3b54086ff0) at /pb2/build/sb_0-18115917-1456812692.68/mysqlcom-pro-5.5.49/sql/item_geofunc.cc:243
#11 0x00000000006b349c in Item::send (this=0x7f3b3c0054d0, protocol=0x3630f98, buffer=0x7f3b54086ff0) at /pb2/build/sb_0-18115917-1456812692.68/mysqlcom-pro-5.5.49/sql/item.cc:5997
#12 0x0000000000515102 in Protocol::send_result_set_row (this=0x3630f98, row_items=<optimized out>) at /pb2/build/sb_0-18115917-1456812692.68/mysqlcom-pro-5.5.49/sql/protocol.cc:847
#13 0x000000000055eecb in select_send::send_data (this=0x7f3b3c005658, items=...) at /pb2/build/sb_0-18115917-1456812692.68/mysqlcom-pro-5.5.49/sql/sql_class.cc:2240
#14 0x00000000005d113f in JOIN::exec (this=0x7f3b3c007c10) at /pb2/build/sb_0-18115917-1456812692.68/mysqlcom-pro-5.5.49/sql/sql_select.cc:1892
#15 0x00000000005d37dd in mysql_select (thd=0x3630af0, rref_pointer_array=0x3632d50, tables=0x0, wild_num=0, fields=..., conds=<optimized out>, og_num=0, order=0x0, group=0x0, having=0x0,
    proc_param=0x0, select_options=2147748608, result=0x7f3b3c005658, unit=0x3632548, select_lex=0x3632b68) at /pb2/build/sb_0-18115917-1456812692.68/mysqlcom-pro-5.5.49/sql/sql_select.cc:2619
#16 0x00000000005d3d17 in handle_select (thd=0x3630af0, lex=0x3632498, result=0x7f3b3c005658, setup_tables_done_option=0)
    at /pb2/build/sb_0-18115917-1456812692.68/mysqlcom-pro-5.5.49/sql/sql_select.cc:297
#17 0x000000000058ae74 in execute_sqlcom_select (thd=0x3630af0, all_tables=0x0) at /pb2/build/sb_0-18115917-1456812692.68/mysqlcom-pro-5.5.49/sql/sql_parse.cc:4625
#18 0x000000000058ea84 in mysql_execute_command (thd=0x3630af0) at /pb2/build/sb_0-18115917-1456812692.68/mysqlcom-pro-5.5.49/sql/sql_parse.cc:2176
#19 0x0000000000593d2d in mysql_parse (thd=0x3630af0, rawbuf=0x7f3b3c004bd0 "SELECT Centroid(AsBinary(LineString(Point(0,0),Point(0,0),Point(0,0))))", length=<optimized out>,
    parser_state=0x7f3b54088c20) at /pb2/build/sb_0-18115917-1456812692.68/mysqlcom-pro-5.5.49/sql/sql_parse.cc:5780
#20 0x000000000059532e in dispatch_command (command=COM_QUERY, thd=0x3630af0, packet=0x36b5f21 "", packet_length=71)
    at /pb2/build/sb_0-18115917-1456812692.68/mysqlcom-pro-5.5.49/sql/sql_parse.cc:1038
#21 0x0000000000596a64 in do_command (thd=0x3630af0) at /pb2/build/sb_0-18115917-1456812692.68/mysqlcom-pro-5.5.49/sql/sql_parse.cc:773
#22 0x000000000063d4a6 in do_handle_one_connection (thd_arg=<optimized out>) at /pb2/build/sb_0-18115917-1456812692.68/mysqlcom-pro-5.5.49/sql/sql_connect.cc:862
#23 0x000000000063d56f in handle_one_connection (arg=<optimized out>) at /pb2/build/sb_0-18115917-1456812692.68/mysqlcom-pro-5.5.49/sql/sql_connect.cc:781
#24 0x00007f3b599bddf5 in start_thread () from /lib64/libpthread.so.0
#25 0x00007f3b58ba660d in clone () from /lib64/libc.so.6
(gdb)
[13 May 2016 6:59] MySQL Verification Team
// 5.5.51 

rm -rf 81407
scripts/mysql_install_db --basedir=/export/umesh/server/binaries/mysql-5.5.51 --datadir=/export/umesh/server/binaries/mysql-5.5.51/81407
bin/mysqld-debug --basedir=/export/umesh/server/binaries/mysql-5.5.51 --datadir=/export/umesh/server/binaries/mysql-5.5.51/81407 --core-file --socket=/tmp/mysql_ushastry.sock  --port=15000 --log-error=/export/umesh/server/binaries/mysql-5.5.51/81407/log.err 2>&1 &

[umshastr@hod03]/export/umesh/server/binaries/mysql-5.5.51: cat docs/INFO_SRC
commit: d91f1d4e32777af0da498818c8098d45c6f64bac
date: 2016-05-04 14:06:45 +0530
build-date: 2016-05-04 23:46:27 +0200
short: d91f1d4
branch: mysql-5.5

MySQL source 5.5.51

-- only debug build affected

Missing separate debuginfos, use: debuginfo-install glibc-2.17-78.0.1.el7.x86_64 libaio-0.3.109-12.el7.x86_64 libgcc-4.8.3-9.el7.x86_64 nss-softokn-freebl-3.16.2.3-13.el7_1.x86_64
(gdb) bt
#0  0x00007f9368f92771 in pthread_kill () from /lib64/libpthread.so.0
#1  0x00000000007ee726 in my_write_core (sig=6) at /pb2/build/sb_0-18781984-1462399238.49/mysql-5.5.51/mysys/stacktrace.c:433
#2  0x00000000006a62dc in handle_fatal_signal (sig=6) at /pb2/build/sb_0-18781984-1462399238.49/mysql-5.5.51/sql/signal_handler.cc:247
#3  <signal handler called>
#4  0x00007f93680b55d7 in raise () from /lib64/libc.so.6
#5  0x00007f93680b6cc8 in abort () from /lib64/libc.so.6
#6  0x00007f93680ae546 in __assert_fail_base () from /lib64/libc.so.6
#7  0x00007f93680ae5f2 in __assert_fail () from /lib64/libc.so.6
#8  0x000000000079a51e in Gis_polygon::centroid_xy (this=0x7f9364057c20, x=0x7f9364057bd8, y=0x7f9364057bd0) at /pb2/build/sb_0-18781984-1462399238.49/mysql-5.5.51/sql/spatial.cc:959
#9  0x000000000079cabd in Gis_polygon::centroid (this=0x1d4b, result=0x7f9364057ff0) at /pb2/build/sb_0-18781984-1462399238.49/mysql-5.5.51/sql/spatial.cc:1017
#10 0x0000000000706425 in Item_func_centroid::val_str (this=0x7f934c0054d0, str=0x7f9364057ff0) at /pb2/build/sb_0-18781984-1462399238.49/mysql-5.5.51/sql/item_geofunc.cc:243
#11 0x00000000006b358c in Item::send (this=0x7f934c0054d0, protocol=0x23cbf68, buffer=0x7f9364057ff0) at /pb2/build/sb_0-18781984-1462399238.49/mysql-5.5.51/sql/item.cc:5998
#12 0x0000000000515122 in Protocol::send_result_set_row (this=0x23cbf68, row_items=<optimized out>) at /pb2/build/sb_0-18781984-1462399238.49/mysql-5.5.51/sql/protocol.cc:847
#13 0x000000000055ef4b in select_send::send_data (this=0x7f934c005658, items=...) at /pb2/build/sb_0-18781984-1462399238.49/mysql-5.5.51/sql/sql_class.cc:2240
#14 0x00000000005d11ef in JOIN::exec (this=0x7f934c007c10) at /pb2/build/sb_0-18781984-1462399238.49/mysql-5.5.51/sql/sql_select.cc:1892
#15 0x00000000005d388d in mysql_select (thd=0x23cbac0, rref_pointer_array=0x23cdd20, tables=0x0, wild_num=0, fields=..., conds=<optimized out>, og_num=0, order=0x0, group=0x0, having=0x0,
    proc_param=0x0, select_options=2147748608, result=0x7f934c005658, unit=0x23cd518, select_lex=0x23cdb38) at /pb2/build/sb_0-18781984-1462399238.49/mysql-5.5.51/sql/sql_select.cc:2619
#16 0x00000000005d3dc7 in handle_select (thd=0x23cbac0, lex=0x23cd468, result=0x7f934c005658, setup_tables_done_option=0)
    at /pb2/build/sb_0-18781984-1462399238.49/mysql-5.5.51/sql/sql_select.cc:297
#17 0x000000000058af24 in execute_sqlcom_select (thd=0x23cbac0, all_tables=0x0) at /pb2/build/sb_0-18781984-1462399238.49/mysql-5.5.51/sql/sql_parse.cc:4625
#18 0x000000000058eb34 in mysql_execute_command (thd=0x23cbac0) at /pb2/build/sb_0-18781984-1462399238.49/mysql-5.5.51/sql/sql_parse.cc:2176
#19 0x0000000000593ddd in mysql_parse (thd=0x23cbac0, rawbuf=0x7f934c004bd0 "SELECT Centroid(AsBinary(LineString(Point(0,0),Point(0,0),Point(0,0))))", length=<optimized out>,
    parser_state=0x7f9364059c20) at /pb2/build/sb_0-18781984-1462399238.49/mysql-5.5.51/sql/sql_parse.cc:5780
#20 0x00000000005953de in dispatch_command (command=COM_QUERY, thd=0x23cbac0, packet=0x2450e31 "", packet_length=71) at /pb2/build/sb_0-18781984-1462399238.49/mysql-5.5.51/sql/sql_parse.cc:1038
#21 0x0000000000596b14 in do_command (thd=0x23cbac0) at /pb2/build/sb_0-18781984-1462399238.49/mysql-5.5.51/sql/sql_parse.cc:773
#22 0x000000000063d556 in do_handle_one_connection (thd_arg=<optimized out>) at /pb2/build/sb_0-18781984-1462399238.49/mysql-5.5.51/sql/sql_connect.cc:862
#23 0x000000000063d61f in handle_one_connection (arg=<optimized out>) at /pb2/build/sb_0-18781984-1462399238.49/mysql-5.5.51/sql/sql_connect.cc:781
#24 0x00007f9368f8ddf5 in start_thread () from /lib64/libpthread.so.0
#25 0x00007f936817660d in clone () from /lib64/libc.so.6
(gdb)
[13 May 2016 6:59] MySQL Verification Team
// 5.6.30/5.7.12 - release/debug not affected
[15 Nov 2017 17:59] Erlend Dahl
Not reproducible on recent 5.7/8.0.
[15 Nov 2017 18:00] Erlend Dahl
There are no plans to backport the fix - the GIS code has been completely rewritten in 5.7/8.0.
[16 Nov 2017 7:45] Roel Van de Paar
If an issue can be repeated on an older release but not a newer one, it would be great if we can avoid the status "can't repeat". 

Ideally;
1) A developer would check whether the bug is actually fixed rather then using a test case verification only
2) Testcase of closed bugs are added to MTR to ensure that future regressions are seen more easily

Even if the ideal of #1 cannot be done, #2 could still be implemented.
[16 Nov 2017 7:46] Roel Van de Paar
Please ignore the last comment, not applicable for this bug.