-
-
Save jtbraun/5e3db389a7e0b3b7fe8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <netcdf.h> | |
// Fails similarly on ubuntu 14.04.02 LTS's HDF5/netcdf libraries and | |
// on the latest github version. | |
// | |
// Config on Ubuntu: | |
// $ dpkg -l '*netcdf*' | |
// /Desired=Unknown/Install/Remove/Purge/Hold | |
// | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend | |
// |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) | |
// ||/ Name Version Architecture Description | |
// +++-==================================-======================-======================-========================================================================= | |
// ii libnetcdf-dev 1:4.1.3-7ubuntu2 amd64 Development kit for NetCDF | |
// un libnetcdf4 <none> <none> (no description available) | |
// un libnetcdf6 <none> <none> (no description available) | |
// ii libnetcdfc++4 1:4.1.3-7ubuntu2 amd64 Interface for scientific data access to large binary data | |
// un libnetcdfc++5 <none> <none> (no description available) | |
// ii libnetcdfc7 1:4.1.3-7ubuntu2 amd64 Interface for scientific data access to large binary data | |
// ii libnetcdff5 1:4.1.3-7ubuntu2 amd64 Interface for scientific data access to large binary data | |
// ii netcdf-bin 1:4.1.3-7ubuntu2 amd64 Programs for reading and writing NetCDF files | |
// un netcdf-doc <none> <none> (no description available) | |
// $ dpkg -l '*hdf5*' | |
// Desired=Unknown/Install/Remove/Purge/Hold | |
// | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend | |
// |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) | |
// ||/ Name Version Architecture Description | |
// +++-==================================-======================-======================-========================================================================= | |
// ii hdf5-helpers 1.8.11-5ubuntu7 amd64 Hierarchical Data Format 5 (HDF5) - Helper tools | |
// un hdf5-tools <none> <none> (no description available) | |
// un libhdf5-1.8 <none> <none> (no description available) | |
// un libhdf5-1.8.4 <none> <none> (no description available) | |
// un libhdf5-1.8.6 <none> <none> (no description available) | |
// un libhdf5-1.8.7 <none> <none> (no description available) | |
// rc libhdf5-7:amd64 1.8.11-5ubuntu7 amd64 Hierarchical Data Format 5 (HDF5) - runtime files - serial version | |
// un libhdf5-dev <none> <none> (no description available) | |
// un libhdf5-doc <none> <none> (no description available) | |
// un libhdf5-mpich2-1.8.4 <none> <none> (no description available) | |
// un libhdf5-mpich2-1.8.6 <none> <none> (no description available) | |
// un libhdf5-mpich2-1.8.7 <none> <none> (no description available) | |
// ii libhdf5-mpich2-7:amd64 1.8.11-5ubuntu7 amd64 Hierarchical Data Format 5 (HDF5) - runtime files - MPICH2 version | |
// ii libhdf5-mpich2-dev 1.8.11-5ubuntu7 amd64 Hierarchical Data Format 5 (HDF5) - development files - MPICH2 version | |
// un libhdf5-serial-1.8.4 <none> <none> (no description available) | |
// un libhdf5-serial-1.8.6 <none> <none> (no description available) | |
// un libhdf5-serial-1.8.7 <none> <none> (no description available) | |
// | |
// | |
// | |
// Just compiled with: | |
// g++ repro.c -o repro -lnetcdf | |
// using the netcdf-c from github (commit | |
// 219a873f8d42245b190dd5ee19ed99812dcbbc90), compiled as below and | |
// verified it still crashed | |
// g++ repro.c ~/src/netcdf/vc/netcdf-c/liblib/.libs/libnetcdf.a -lhdf5 -lhdf5_hl -lmpi -lcurl -o repro | |
// | |
// By default, runs all seven tests. Accepts a single optional | |
// integer argument MASK (which may be hex) that selects which of the | |
// seven tests to run. | |
// | |
void | |
check_err(const int stat, const int line, const char *file) { | |
if (stat != NC_NOERR) { | |
(void)fprintf(stderr,"line %d of %s: %s\n", line, file, nc_strerror(stat)); | |
fflush(stderr); | |
exit(1); | |
} | |
} | |
void | |
run_test(const char *testname, | |
bool v1unicode, | |
bool v2unicode, | |
bool deletefirst | |
) { | |
int stat; /* return status */ | |
int ncid; /* netCDF id */ | |
/* group ids */ | |
int root_grp; | |
/* dimension ids */ | |
int dim_dim; | |
/* dimension lengths */ | |
size_t dim_len = 10; | |
/* variable ids */ | |
int var_id; | |
/* rank (number of dimensions) for each variable */ | |
# define RANK_var 1 | |
/* variable shapes */ | |
int var_dims[RANK_var]; | |
printf("Beginning test %s\n", testname); | |
/* enter define mode */ | |
stat = nc_create("test.nc", NC_CLOBBER|NC_NETCDF4, &ncid); | |
check_err(stat,__LINE__,__FILE__); | |
root_grp = ncid; | |
/* define dimensions */ | |
stat = nc_def_dim(root_grp, "dim", dim_len, &dim_dim); | |
check_err(stat,__LINE__,__FILE__); | |
/* define variables */ | |
var_dims[0] = dim_dim; | |
stat = nc_def_var(root_grp, "var", NC_DOUBLE, RANK_var, var_dims, &var_id); | |
check_err(stat,__LINE__,__FILE__); | |
/* assign per-variable attributes */ | |
{ /* _FillValue */ | |
static const double var_FillValue_att[1] = {-1} ; | |
stat = nc_put_att_double(root_grp, var_id, "_FillValue", NC_DOUBLE, 1, var_FillValue_att); | |
check_err(stat,__LINE__,__FILE__); | |
} | |
printf("1st pass: calling "); | |
if (v1unicode) { | |
printf("nc_put_att_string"); | |
{ /* att */ | |
static const char* var_att_att[1] = {"foo"} ; | |
stat = nc_put_att_string(root_grp, var_id, "att", 1, var_att_att); check_err(stat,__LINE__,__FILE__); | |
} | |
} else { | |
printf("nc_put_att_text"); | |
{ /* att */ | |
stat = nc_put_att_text(root_grp, var_id, "att", 3, "foo"); | |
check_err(stat,__LINE__,__FILE__); | |
} | |
} | |
printf("\n"); | |
if (deletefirst) { | |
printf("Deleting attribute\n"); | |
stat = nc_del_att(root_grp, var_id, "att"); | |
check_err(stat,__LINE__,__FILE__); | |
} | |
printf("2nd pass: calling "); | |
if (v2unicode) { | |
printf("nc_put_att_string"); | |
{ /* att */ | |
static const char* var_att_att[1] = {"foo"} ; | |
stat = nc_put_att_string(root_grp, var_id, "att", 1, var_att_att); check_err(stat,__LINE__,__FILE__); | |
} | |
} else { | |
printf("nc_put_att_text"); | |
{ /* att */ | |
stat = nc_put_att_text(root_grp, var_id, "att", 3, "foo"); | |
check_err(stat,__LINE__,__FILE__); | |
} | |
} | |
printf("\n"); | |
/* leave define mode */ | |
stat = nc_enddef (root_grp); | |
check_err(stat,__LINE__,__FILE__); | |
/* assign variable data */ | |
stat = nc_close(root_grp); | |
check_err(stat,__LINE__,__FILE__); | |
printf("\n"); | |
} | |
int | |
main(int argc, char *argv[]) { | |
int count = -1; | |
if (argc > 1) { | |
count = strtol(argv[1], NULL, 0); | |
printf("TEST MASK %x\n", count); | |
} | |
for (int pass = 0; pass < 3; ++pass) { | |
if (count < 0 || (count & (1 << 0))) | |
run_test("0 SSF", false, false, false); // OKAY | |
if (count < 0 || (count & (1 << 1))) | |
run_test("1 UUF", true, true, false); // OKAY | |
if (count < 0 || (count & (1 << 2))) | |
run_test("2 SST", false, false, true); // OKAY | |
if (count < 0 || (count & (1 << 3))) | |
run_test("3 UUT", true, true, true); // OKAY | |
if (count < 0 || (count & (1 << 4))) | |
run_test("4 UST", true, false, true); // OKAY | |
if (count < 0 || (count & (1 << 5))) | |
run_test("5 SUT", false, true, true); // OKAY | |
if (count < 0 || (count & (1 << 6))) | |
run_test("6 USF", true, false, false); | |
if (count < 0 || (count & (1 << 7))) | |
run_test("7 SUT", false, true, false); // CRASH | |
} | |
return 0; | |
} | |
/* | |
Test 6, ubuntu netcdf | |
Crashes reliably. | |
Fixed in latest, maybe? | |
TEST MASK ff | |
Beginning test 0 SSF | |
1st pass: calling nc_put_att_text | |
2nd pass: calling nc_put_att_text | |
Beginning test 1 UUF | |
1st pass: calling nc_put_att_string | |
2nd pass: calling nc_put_att_string | |
Beginning test 2 SST | |
1st pass: calling nc_put_att_text | |
Deleting attribute | |
2nd pass: calling nc_put_att_text | |
Beginning test 3 UUT | |
1st pass: calling nc_put_att_string | |
Deleting attribute | |
2nd pass: calling nc_put_att_string | |
Beginning test 4 UST | |
1st pass: calling nc_put_att_string | |
Deleting attribute | |
2nd pass: calling nc_put_att_text | |
Beginning test 5 SUT | |
1st pass: calling nc_put_att_text | |
Deleting attribute | |
2nd pass: calling nc_put_att_string | |
Beginning test 6 USF | |
1st pass: calling nc_put_att_string | |
2nd pass: calling nc_put_att_text | |
*** Error in `repro_ubuntu': munmap_chunk(): invalid pointer: 0x0000000000641890 *** | |
Program received signal SIGABRT, Aborted. | |
0x00007ffff770ecc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 | |
56 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory. | |
(gdb) bt | |
#0 0x00007ffff770ecc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 | |
#1 0x00007ffff77120d8 in __GI_abort () at abort.c:89 | |
#2 0x00007ffff774b394 in __libc_message (do_abort=do_abort@entry=1, fmt=fmt@entry=0x7ffff7859b28 "*** Error in `%s': %s: 0x%s ***\n") | |
at ../sysdeps/posix/libc_fatal.c:175 | |
#3 0x00007ffff77560f7 in malloc_printerr (action=<optimized out>, str=0x7ffff7859ea8 "munmap_chunk(): invalid pointer", ptr=<optimized out>) at malloc.c:4996 | |
#4 0x00007ffff7b258b0 in nc4_att_list_del () from /usr/lib/libnetcdf.so.7 | |
#5 0x00007ffff7b259f4 in nc4_rec_grp_del () from /usr/lib/libnetcdf.so.7 | |
#6 0x00007ffff7b1f461 in ?? () from /usr/lib/libnetcdf.so.7 | |
#7 0x00007ffff7b2062c in NC4_close () from /usr/lib/libnetcdf.so.7 | |
#8 0x00007ffff7ad6da3 in nc_close () from /usr/lib/libnetcdf.so.7 | |
#9 0x0000000000400ec9 in run_test(char const*, bool, bool, bool) () | |
#10 0x000000000040105b in main () | |
*/ | |
/* | |
Test 7, latest netcdf | |
Doesn't crash reliably. Seems to work okay if just test 7 was run (MASK = 0x80), | |
ubuntu: I've seen a crash in this location, but not while connected | |
to GDB to provide a stack trace. | |
TEST MASK c0 | |
Beginning test 6 USF | |
1st pass: calling nc_put_att_string | |
2nd pass: calling nc_put_att_text | |
Beginning test 7 SUT | |
1st pass: calling nc_put_att_text | |
2nd pass: calling nc_put_att_string | |
Program received signal SIGSEGV, Segmentation fault. | |
strlen () at ../sysdeps/x86_64/strlen.S:106 | |
106 ../sysdeps/x86_64/strlen.S: No such file or directory. | |
(gdb) bt | |
#0 strlen () at ../sysdeps/x86_64/strlen.S:106 | |
#1 0x00007ffff7ae0838 in H5T__conv_vlen () from /usr/lib/x86_64-linux-gnu/libhdf5.so.7 | |
#2 0x00007ffff7ad520c in H5T_convert () from /usr/lib/x86_64-linux-gnu/libhdf5.so.7 | |
#3 0x00007ffff795fb47 in H5Awrite () from /usr/lib/x86_64-linux-gnu/libhdf5.so.7 | |
#4 0x000000000043105d in put_att_grpa (att=0x374aae0, varid=0, grp=0x3755310) at nc4hdf.c:1332 | |
#5 write_attlist (attlist=<optimized out>, varid=0, grp=grp@entry=0x3755310) at nc4hdf.c:1360 | |
#6 0x00000000004352ac in var_create_dataset (grp=grp@entry=0x3755310, var=var@entry=0x374a9e0, write_dimid=write_dimid@entry=NC_FALSE) at nc4hdf.c:1701 | |
#7 0x0000000000435b24 in write_var (write_dimid=NC_FALSE, grp=<optimized out>, var=0x374a9e0) at nc4hdf.c:2272 | |
#8 nc4_rec_write_metadata (grp=<optimized out>, bad_coord_order=NC_FALSE) at nc4hdf.c:2577 | |
#9 0x000000000042b927 in sync_netcdf4_file (h5=0x374a850) at nc4file.c:3000 | |
#10 0x000000000042f22e in nc4_enddef_netcdf4_file (h5=<optimized out>) at nc4file.c:3315 | |
#11 0x000000000042f282 in NC4_enddef (ncid=<optimized out>) at nc4file.c:2958 | |
#12 0x0000000000406e82 in nc_enddef (ncid=65536) at dfile.c:907 | |
#13 0x0000000000405fa8 in run_test(char const*, bool, bool, bool) () | |
#14 0x0000000000406186 in main () | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import netCDF4 as nc | |
def run_test(testname, v1, v2, delfirst=False): | |
ds = nc.Dataset("test.nc", 'w') | |
ds.createDimension('dim', 10) | |
v = ds.createVariable('var', 'd', | |
dimensions=('dim',), | |
fill_value=-1) | |
attname = 'att' | |
v.setncattr(attname, v1) | |
att = v.getncattr(attname) | |
print testname, "AFTER FIRST", type(att), att | |
if delfirst: | |
v.delncattr(attname) | |
v.setncattr(attname, v2) | |
att = v.getncattr(attname) | |
print testname, "AFTER SECOND", type(att), att | |
ds.close() | |
run_test('0 SSF', 'foo', 'bar') # OKAY | |
# run_test('1 UUF', u'foo', u'bar') # OKAY | |
# run_test('2 SST', 'foo', 'bar', True) # OKAY | |
# run_test('3 UUT', u'foo', u'bar', True) # OKAY | |
# run_test('4 UST', u'foo', 'bar', True) # OKAY | |
# run_test('5 SUT', 'foo', u'bar', True) # OKAY | |
#run_test('6 USF', u'foo', 'bar') # CRASH, always, at getncattr(attname) the second time | |
#run_test('7 SUT', 'foo', u'bar') # CRASH, sometimes, at close, not at fetch | |
# 6 callstack | |
# 6 USF AFTER FIRST <type 'unicode'> foo | |
# 6 USF AFTER SECOND <type 'unicode'> | |
# *** Error in `/usr/bin/python': free(): invalid pointer: 0x00007ffff7bb57b8 *** | |
# | |
# Program received signal SIGABRT, Aborted. | |
# 0x00007ffff782dcc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 | |
# 56 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory. | |
# (gdb) bt | |
# #0 0x00007ffff782dcc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 | |
# #1 0x00007ffff78310d8 in __GI_abort () at abort.c:89 | |
# #2 0x00007ffff786a394 in __libc_message (do_abort=do_abort@entry=1, fmt=fmt@entry=0x7ffff7978b28 "*** Error in `%s': %s: 0x%s ***\n") | |
# at ../sysdeps/posix/libc_fatal.c:175 | |
# #3 0x00007ffff787666e in malloc_printerr (ptr=<optimized out>, str=0x7ffff7974c19 "free(): invalid pointer", action=1) at malloc.c:4996 | |
# #4 _int_free (av=<optimized out>, p=<optimized out>, have_lock=0) at malloc.c:3840 | |
# #5 0x00007ffff660b8b0 in nc4_att_list_del () from /usr/lib/libnetcdf.so.7 | |
# #6 0x00007ffff660b9f4 in nc4_rec_grp_del () from /usr/lib/libnetcdf.so.7 | |
# #7 0x00007ffff6605461 in ?? () from /usr/lib/libnetcdf.so.7 | |
# #8 0x00007ffff660662c in NC4_close () from /usr/lib/libnetcdf.so.7 | |
# #9 0x00007ffff65bcda3 in nc_close () from /usr/lib/libnetcdf.so.7 | |
# #10 0x00007ffff68dba35 in __pyx_pf_7netCDF4_8_netCDF4_7Dataset_14close (__pyx_v_self=0x7fffecd34910, __pyx_v_self=0x7fffecd34910) | |
# at netCDF4/_netCDF4.c:11843 | |
# #11 __pyx_pw_7netCDF4_8_netCDF4_7Dataset_15close (__pyx_v_self=0x7fffecd34910, unused=<optimized out>) at netCDF4/_netCDF4.c:11816 | |
# #12 0x000000000049a3b5 in PyEval_EvalFrameEx () | |
# #13 0x00000000004a090c in PyEval_EvalCodeEx () | |
# #14 0x0000000000499a52 in PyEval_EvalFrameEx () | |
# #15 0x00000000004a1634 in ?? () | |
# #16 0x000000000044e4a5 in PyRun_FileExFlags () | |
# #17 0x000000000044ec9f in PyRun_SimpleFileExFlags () | |
# #18 0x000000000044f904 in Py_Main () | |
# #19 0x00007ffff7818ec5 in __libc_start_main (main=0x44f9c2 <main>, argc=2, argv=0x7fffffffd898, init=<optimized out>, fini=<optimized out>, | |
# rtld_fini=<optimized out>, stack_end=0x7fffffffd888) at libc-start.c:287 | |
# #20 0x0000000000578c4e in _start () | |
# (gdb) | |
# 7 callstack | |
# | |
# 7 SUT AFTER FIRST <type 'unicode'> foo | |
# 7 SUT AFTER SECOND <type 'unicode'> bar | |
# | |
# Program received signal SIGSEGV, Segmentation fault. | |
# strlen () at ../sysdeps/x86_64/strlen.S:106 | |
# 106 ../sysdeps/x86_64/strlen.S: No such file or directory. | |
# (gdb) bt | |
# #0 strlen () at ../sysdeps/x86_64/strlen.S:106 | |
# #1 0x00007ffff6059838 in H5T__conv_vlen () from /usr/lib/x86_64-linux-gnu/libhdf5.so.7 | |
# #2 0x00007ffff604e20c in H5T_convert () from /usr/lib/x86_64-linux-gnu/libhdf5.so.7 | |
# #3 0x00007ffff5ed8b47 in H5Awrite () from /usr/lib/x86_64-linux-gnu/libhdf5.so.7 | |
# #4 0x00007ffff660d03e in ?? () from /usr/lib/libnetcdf.so.7 | |
# #5 0x00007ffff66101ee in nc4_rec_write_metadata () from /usr/lib/libnetcdf.so.7 | |
# #6 0x00007ffff66053d9 in ?? () from /usr/lib/libnetcdf.so.7 | |
# #7 0x00007ffff660544d in ?? () from /usr/lib/libnetcdf.so.7 | |
# #8 0x00007ffff660662c in NC4_close () from /usr/lib/libnetcdf.so.7 | |
# #9 0x00007ffff65bcda3 in nc_close () from /usr/lib/libnetcdf.so.7 | |
# #10 0x00007ffff68dba35 in __pyx_pf_7netCDF4_8_netCDF4_7Dataset_14close (__pyx_v_self=0x7fffecd34910, __pyx_v_self=0x7fffecd34910) at netCDF4/_netCDF4.c:11843 | |
# #11 __pyx_pw_7netCDF4_8_netCDF4_7Dataset_15close (__pyx_v_self=0x7fffecd34910, unused=<optimized out>) at netCDF4/_netCDF4.c:11816 | |
# #12 0x000000000049a3b5 in PyEval_EvalFrameEx () | |
# #13 0x00000000004a090c in PyEval_EvalCodeEx () | |
# #14 0x0000000000499a52 in PyEval_EvalFrameEx () | |
# #15 0x00000000004a1634 in ?? () | |
# #16 0x000000000044e4a5 in PyRun_FileExFlags () | |
# #17 0x000000000044ec9f in PyRun_SimpleFileExFlags () | |
# #18 0x000000000044f904 in Py_Main () | |
# #19 0x00007ffff7818ec5 in __libc_start_main (main=0x44f9c2 <main>, argc=2, argv=0x7fffffffd898, init=<optimized out>, fini=<optimized out>, | |
# rtld_fini=<optimized out>, stack_end=0x7fffffffd888) at libc-start.c:287 | |
# #20 0x0000000000578c4e in _start () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment