Bug #674

psxy -SqxFILE segfault if FILE doesn't exist or doesn't contain coordinates

Added by Kristof almost 3 years ago. Updated over 2 years ago.

Status:ClosedStart date:2015-02-12
Priority:NormalDue date:
Assignee:Paul% Done:

100%

Category:-
Target version:Candidate for next bugfix release
Affected version:5.2-svn Platform:

Description

During doing some more troubleshooting on the problem in my posting gmt 5.2-svn: psxy -Sqx – malloc: memory corruption I found something I consider a bug:

Observed behavior

When using psxy -SqxFILE and FILE contains only one coordinate and not a coordinate pair, the call fails beautifully with an error message:

$ ./psxy_crash.sh
psxy: Error: nl = 0
$

But when using psxy -SqxFILE and FILE
  • doesn't exist at all
  • contains only
    • a comment
    • an empty line
    • a ">"
    • a part of a coordinate (LON or LAT)

the psxy call ends abruptly in a segfault:

$ ./psxy_crash.sh
ERROR: Caught signal number 11 (Segmentation fault) at
/opt/gmt-5.2.0-r14060//lib/libgmt.so.5(GMT_contlabel_prep+0x7b0)[0x7f51b9dd7800]
[0x10]
Stack backtrace:
/opt/gmt-5.2.0-r14060//lib/libgmt.so.5(sig_handler+0x137)[0x7f51b9d35ee7]
/lib/x86_64-linux-gnu/libc.so.6(+0x36150)[0x7f51b9961150]
/opt/gmt-5.2.0-r14060//lib/libgmt.so.5(GMT_contlabel_prep+0x7b0)[0x7f51b9dd7800]
/opt/gmt-5.2.0-r14060//lib/libgmt.so.5(GMT_psxy+0x3cf1)[0x7f51b9f84421]
/opt/gmt-5.2.0-r14060//lib/libgmt.so.5(GMT_Call_Module+0x178)[0x7f51b9d39b58]
psxy(main+0x1f7)[0x400d87]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7f51b994c76d]
psxy[0x4013f1]
$

Expected behavior

I'd expect psxy to fail similar to the first case in case FILE doesn't exist or proper parsing of FILE fails.

I attached a test script with the six different cases listed above. Just uncomment the desired case in the script.

All the best,
Kristof

psxy_crash.sh Magnifier - test script with the different cases listed above (1.75 KB) Kristof, 2015-02-12 00:55

Associated revisions

Revision 14063
Added by Paul almost 3 years ago

Improve error handling for -Sqx|f in psxy, see issue #674

Revision 14683
Added by Paul over 2 years ago

Strengthen checking for bad file, lacking records or columns in support of issue #674

History

#1 Updated by Kristof almost 3 years ago

I didn't include any infos on the system:

  • Ubuntu 12.04.5 LTS (GNU/Linux 2.6.32-042stab094.8 x86_64)
  • GMT Version 5.2.0_r14060 [64-bit] [4 cores]

#2 Updated by Paul almost 3 years ago

  • Status changed from New to Resolved
  • Assignee set to Paul
  • Target version set to Candidate for next bugfix release
  • % Done changed from 0 to 100

I added a more graceful exit in r14064.
Note that the first error message I get is
psxy: Cannot open file label_helper_fir_id.d
ERROR: Caught signal number 11 (Segmentation fault) at
...
Did you miss that?

#3 Updated by Kristof almost 3 years ago

Paul wrote:

[…]
Note that the first error message I get is
psxy: Cannot open file label_helper_fir_id.d
[…]

Not here - on my machine I only get the segfault. Additionally I see no string containing "label_helper_fir_id.d" in the script psxy_crash.sh attached to this bug? Where does this come from? Even when I create no helper file I only get the segfault in r14060.

#4 Updated by Paul almost 3 years ago

Interesting. Oh, the label_helper_fir_id.d is just any non-existing file; could have been nofile.txt, I just cut your S option down to that.
If you give a nonesistant file you will run into this section:
if ((fp = GMT_fopen (GMT, file, open_mode)) == NULL) {
GMT_Report (GMT
>parent, GMT_MSG_NORMAL, "Cannot open file %s\n", file);
if (!use_GMT_io) GMT→current.io.input = psave; /* Restore previous setting */
return (NULL);
}
so it is hard for me to understand why you do not get that error message, unless you are running with -Vq.

#5 Updated by Kristof almost 3 years ago

Maybe I don't get your point but when I comment everything out that creates a helper file in above posted script, I only get rm complaining that there is no file to delete.

Copy & paste from the shell running above script psxy_crash.sh with everything commented out generating a file of the name FIRhelper.d:

kristof@[redacted]$ ./psxy_crash.sh
ERROR: Caught signal number 11 (Segmentation fault) at
/usr/lib/libnetcdf.so.6(clearnccache+0xf)[0x7fdb6f5c147f]
[0x48]
Stack backtrace:
/opt/gmt-5.2.0-r14060//lib/libgmt.so.5(sig_handler+0x137)[0x7fdb6fc87ee7]
/lib/x86_64-linux-gnu/libc.so.6(+0x36150)[0x7fdb6f8b3150]
/usr/lib/libnetcdf.so.6(clearnccache+0xf)[0x7fdb6f5c147f]
/usr/lib/libnetcdf.so.6(freeNCDRNO3+0xd)[0x7fdb6f5bc68d]
/usr/lib/libnetcdf.so.6(nc4d_open_file+0x87)[0x7fdb6f5d04f7]
/usr/lib/libnetcdf.so.6(nc_open+0x1f)[0x7fdb6f583d1f]
/opt/gmt-5.2.0-r14060//lib/libgmt.so.5(gmt_nc_fopen+0x2e2)[0x7fdb6fcc1002]
/opt/gmt-5.2.0-r14060//lib/libgmt.so.5(GMT_fopen+0x131)[0x7fdb6fcc20c1]
/opt/gmt-5.2.0-r14060//lib/libgmt.so.5(GMT_read_table+0x1a9)[0x7fdb6fcd4089]
/opt/gmt-5.2.0-r14060//lib/libgmt.so.5(GMT_contlabel_prep+0x7b0)[0x7fdb6fd29800]
/opt/gmt-5.2.0-r14060//lib/libgmt.so.5(GMT_psxy+0x3cf1)[0x7fdb6fed6421]
/opt/gmt-5.2.0-r14060//lib/libgmt.so.5(GMT_Call_Module+0x178)[0x7fdb6fc8bb58]
psxy(main+0x1f7)[0x400d87]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7fdb6f89e76d]
psxy[0x4013f1]
rm: cannot remove `FIRhelper.d': No such file or directory
kristof@[redacted]$

Please note that I'm still on r14060 - maybe it was introduced in r14062 already? Didn't check.

#6 Updated by Kristof almost 3 years ago

I added -Vd to catch every message, even then no complaining about the missing helper file:

kristof@[redacted]$ ./psxy_crash.sh
psxy: GMT: 1. GMT_getsharepath trying current dir
psxy: GMT: 4. GMT_getsharepath trying SHAREDIR subdir /opt/gmt-5.2.0-r14060//share/localization
psxy: The PROJ_GEODESIC set to Vincenty
psxy: GMT: 1. GMT_getsharepath trying current dir
psxy: GMT: 4. GMT_getsharepath trying SHAREDIR subdir /opt/gmt-5.2.0-r14060//share/pslib
psxy: GMT: 1. GMT_getsharepath trying current dir
psxy: GMT: 4. GMT_getsharepath trying SHAREDIR subdir /opt/gmt-5.2.0-r14060//share/localization
psxy: The PROJ_GEODESIC set to Vincenty
psxy: GMT: 1. GMT_getsharepath trying current dir
psxy: GMT: 4. GMT_getsharepath trying SHAREDIR subdir /opt/gmt-5.2.0-r14060//share/pslib
psxy: GMT_Create_Session initialized GMT structure
psxy: Shared Library # 0 (core). Path = libgmt.so
psxy: Loading core GMT shared library: libgmt.so
psxy: Loading GMT plugins from: /opt/gmt-5.2.0-r14060/lib/gmt/plugins
psxy: Shared Library # 1 (supplements). Path =
psxy: History: Process -J.
psxy: History: Process -R.
psxy: Processing input table data
psxy: Operation will require 2 input columns [n_cols_start = 2]
psxy: Projected values in meters: -6.21163e+06 -2.00498e+06 -2.83328e+06 98181.4
ERROR: Caught signal number 11 (Segmentation fault) at
/usr/lib/libnetcdf.so.6(clearnccache+0xf)[0x7fbee21a647f]
[0x48]
Stack backtrace:
/opt/gmt-5.2.0-r14060//lib/libgmt.so.5(sig_handler+0x137)[0x7fbee286cee7]
/lib/x86_64-linux-gnu/libc.so.6(+0x36150)[0x7fbee2498150]
/usr/lib/libnetcdf.so.6(clearnccache+0xf)[0x7fbee21a647f]
/usr/lib/libnetcdf.so.6(freeNCDRNO3+0xd)[0x7fbee21a168d]
/usr/lib/libnetcdf.so.6(nc4d_open_file+0x87)[0x7fbee21b54f7]
/usr/lib/libnetcdf.so.6(nc_open+0x1f)[0x7fbee2168d1f]
/opt/gmt-5.2.0-r14060//lib/libgmt.so.5(gmt_nc_fopen+0x2e2)[0x7fbee28a6002]
/opt/gmt-5.2.0-r14060//lib/libgmt.so.5(GMT_fopen+0x131)[0x7fbee28a70c1]
/opt/gmt-5.2.0-r14060//lib/libgmt.so.5(GMT_read_table+0x1a9)[0x7fbee28b9089]
/opt/gmt-5.2.0-r14060//lib/libgmt.so.5(GMT_contlabel_prep+0x7b0)[0x7fbee290e800]
/opt/gmt-5.2.0-r14060//lib/libgmt.so.5(GMT_psxy+0x3cf1)[0x7fbee2abb421]
/opt/gmt-5.2.0-r14060//lib/libgmt.so.5(GMT_Call_Module+0x178)[0x7fbee2870b58]
psxy(main+0x1f7)[0x400d87]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7fbee248376d]
psxy[0x4013f1]
rm: cannot remove `FIRhelper.d': No such file or directory
kristof@[redacted]$
Alterations to psxy_crash.sh:
  • commented everything out creating file FIRhelper.d
  • added -Vd to the psxy call

#7 Updated by Paul almost 3 years ago

Yes, in r14064 for sure.
Looking more closely at your traceback it says libnetcdf is complaining and that failure happens in gmt_nc_open. Does your command use a netcdf file and you are using -bc or someting?

#8 Updated by Kristof almost 3 years ago

Well, I updated to r14064 and see no real difference in the output. There is no netcdf file involved as far as I can see.

kristof@[redacted]$ gmt --version
5.2.0_r14064
kristof@[redacted]$ ./psxy_crash.sh
psxy: GMT: 1. GMT_getsharepath trying current dir
psxy: GMT: 4. GMT_getsharepath trying SHAREDIR subdir /opt/gmt-5.2.0-r14064//share/localization
psxy: The PROJ_GEODESIC set to Vincenty
psxy: GMT: 1. GMT_getsharepath trying current dir
psxy: GMT: 4. GMT_getsharepath trying SHAREDIR subdir /opt/gmt-5.2.0-r14064//share/pslib
psxy: GMT: 1. GMT_getsharepath trying current dir
psxy: GMT: 4. GMT_getsharepath trying SHAREDIR subdir /opt/gmt-5.2.0-r14064//share/localization
psxy: The PROJ_GEODESIC set to Vincenty
psxy: GMT: 1. GMT_getsharepath trying current dir
psxy: GMT: 4. GMT_getsharepath trying SHAREDIR subdir /opt/gmt-5.2.0-r14064//share/pslib
psxy: GMT_Create_Session initialized GMT structure
psxy: Shared Library # 0 (core). Path = libgmt.so
psxy: Loading core GMT shared library: libgmt.so
psxy: Loading GMT plugins from: /opt/gmt-5.2.0-r14064/lib/gmt/plugins
psxy: Shared Library # 1 (supplements). Path =
psxy: History: Process -J.
psxy: History: Process -R.
psxy: Processing input table data
psxy: Operation will require 2 input columns [n_cols_start = 2]
psxy: Projected values in meters: -6.21163e+06 -2.00498e+06 -2.83328e+06 98181.4
ERROR: Caught signal number 11 (Segmentation fault) at
/usr/lib/libnetcdf.so.6(clearnccache+0xf)[0x7f17a090b47f]
[0x48]
Stack backtrace:
/opt/gmt-5.2.0-r14064//lib/libgmt.so.5(sig_handler+0x137)[0x7f17a0fd1ee7]
/lib/x86_64-linux-gnu/libc.so.6(+0x36150)[0x7f17a0bfd150]
/usr/lib/libnetcdf.so.6(clearnccache+0xf)[0x7f17a090b47f]
/usr/lib/libnetcdf.so.6(freeNCDRNO3+0xd)[0x7f17a090668d]
/usr/lib/libnetcdf.so.6(nc4d_open_file+0x87)[0x7f17a091a4f7]
/usr/lib/libnetcdf.so.6(nc_open+0x1f)[0x7f17a08cdd1f]
/opt/gmt-5.2.0-r14064//lib/libgmt.so.5(gmt_nc_fopen+0x2e2)[0x7f17a100b132]
/opt/gmt-5.2.0-r14064//lib/libgmt.so.5(GMT_fopen+0x131)[0x7f17a100c1f1]
/opt/gmt-5.2.0-r14064//lib/libgmt.so.5(GMT_read_table+0x1a9)[0x7f17a101e1b9]
/opt/gmt-5.2.0-r14064//lib/libgmt.so.5(GMT_contlabel_prep+0x6d3)[0x7f17a1073913]
/opt/gmt-5.2.0-r14064//lib/libgmt.so.5(GMT_psxy+0x3cf1)[0x7f17a12205f1]
/opt/gmt-5.2.0-r14064//lib/libgmt.so.5(GMT_Call_Module+0xe8)[0x7f17a0fd5b48]
psxy(main+0x1f7)[0x400d87]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7f17a0be876d]
psxy[0x4013f1]
rm: cannot remove `FIRhelper.d': No such file or directory
kristof@[redacted]$

#9 Updated by Paul almost 3 years ago

I understand there is no netCDF file involved. But nevertheless the code crashes inside gmt_nc_fopen. I do not understand why it is going in there for you under Linux and not for me under OSX when the file does not exist. I will try to run in debug. Busy day here unfortunately with classes etc.

#10 Updated by Paul over 2 years ago

I've added some more checks in r14683 (GMT 5.2). All your cases now gracefully print meaningful error messages and exit. I also added this for -Sqf. Please update and check if there are more issues so we can update this old issue.

#11 Updated by Remko over 2 years ago

  • Status changed from Resolved to Closed

Closed by verification.

Also available in: Atom PDF