Bug #542

grdpaste segmentation fault

Added by Eduardo over 3 years ago. Updated over 3 years ago.

Status:ClosedStart date:2014-04-16
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-
Target version:Candidate for next bugfix release
Affected version:5.x-svn Platform:Linux

Description


grdpaste srtm_22_21.tif=gd srtm_23_21.tif=gd -Gsrtm_2223_21.grd -fg -V
grdpaste: Processing input grids
grdpaste: File W E S N dx dy nx ny
grdpaste: srtm_22_21.tif=gd -74.9999998547 -69.9999998547 -44.9999997579 -39.9999997579 0.000833333333333 0.000833333333333 6001 6001
grdpaste: srtm_23_21.tif=gd -69.9999997337 -64.9999997337 -44.9999997579 -39.9999997579 0.000833333333333 0.000833333333333 6001 6001
grdpaste: srtm_2223_21.grd -74.9999998547 -64.9999997337 -44.9999997579 -39.9999997579 0.000833333333333 0.000833333333333 12002 6001
[Session grdpaste (0)]: Error returned from GMT API: GMT_GRID_READ_ERROR (18)
ERROR: Caught signal number 11 (Segmentation fault) at
/lib/i386-linux-gnu/i686/cmov/libc.so.6(cfree+0x26)[0xb63c46e6]
[0xa066b01c]
Stack backtrace:
/opt/apps/GMT/GMT-5-testing/bin/../lib/i386-linux-gnu/libgmt.so.5(sig_handler+0x18e)[0xb741a75e]
linux-gate.so.1(__kernel_rt_sigreturn+0x0)[0xb776240c]
/lib/i386-linux-gnu/i686/cmov/libc.so.6(cfree+0x26)[0xb63c46e6]
/usr/lib/i386-linux-gnu/libfftw3f.so.3(fftwf_kernel_free+0x1b)[0xb65c70cb]
/usr/lib/i386-linux-gnu/libfftw3f.so.3(fftwf_free+0x1b)[0xb666dcab]
/opt/apps/GMT/GMT-5-testing/bin/../lib/i386-linux-gnu/libgmt.so.5(GMT_free_func+0x35)[0xb7471e95]
/opt/apps/GMT/GMT-5-testing/bin/../lib/i386-linux-gnu/libgmt.so.5(GMT_free_grid_ptr+0xce)[0xb745554e]
/opt/apps/GMT/GMT-5-testing/bin/../lib/i386-linux-gnu/libgmt.so.5(GMTAPI_destroy_data_ptr+0xd7)[0xb741d0a7]
/opt/apps/GMT/GMT-5-testing/bin/../lib/i386-linux-gnu/libgmt.so.5(GMT_Garbage_Collection+0x1f5)[0xb7422475]
/opt/apps/GMT/GMT-5-testing/bin/../lib/i386-linux-gnu/libgmt.so.5(GMT_end_module+0x52)[0xb74effd2]
/opt/apps/GMT/GMT-5-testing/bin/../lib/i386-linux-gnu/libgmt.so.5(GMT_grdpaste+0x100)[0xb75dc270]
/opt/apps/GMT/GMT-5-testing/bin/../lib/i386-linux-gnu/libgmt.so.5(GMT_Call_Module+0xd9)[0xb742f809]
grdpaste(main+0x2d3)[0x8048be3]
/lib/i386-linux-gnu/i686/cmov/libc.so.6(__libc_start_main+0xf3)[0xb6367a63]
grdpaste[0x8049014]

I don't know why there is a reference to libfftw3f.so.3...

valgrind grdpaste srtm_22_21.tif=gd srtm_23_21.tif=gd -Gsrtm_2223_21.grd -fg -V
24725 Memcheck, a memory error detector
24725 Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
24725 Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
24725 Command: grdpaste srtm_22_21.tif=gd srtm_23_21.tif=gd -Gsrtm_2223_21.grd -fg -V
24725
grdpaste: Processing input grids
grdpaste: File W E S N dx dy nx ny
grdpaste: srtm_22_21.tif=gd -74.9999998547 -69.9999998547 -44.9999997579 -39.9999997579 0.000833333333333 0.000833333333333 6001 6001
grdpaste: srtm_23_21.tif=gd -69.9999997337 -64.9999997337 -44.9999997579 -39.9999997579 0.000833333333333 0.000833333333333 6001 6001
grdpaste: srtm_2223_21.grd -74.9999998547 -64.9999997337 -44.9999997579 -39.9999997579 0.000833333333333 0.000833333333333 12002 6001
24725 Warning: set address range perms: large range [0xe4af060, 0x1f7691a4) (undefined)
[Session grdpaste (0)]: Error returned from GMT API: GMT_GRID_READ_ERROR (18)
24725 Warning: set address range perms: large range [0xe4af04c, 0x1f7691b8) (noaccess)
24725 Invalid free() / delete / delete[] / realloc()
24725 at 0x4029DA8: free (vg_replace_malloc.c:468)
24725 by 0x50080CA: fftwf_kernel_free (in /usr/lib/i386-linux-gnu/libfftw3f.so.3.3.2)
24725 by 0x50AECAA: fftwf_free (in /usr/lib/i386-linux-gnu/libfftw3f.so.3.3.2)
24725 by 0x40BDE94: GMT_free_func (gmt_memory.c:585)
24725 by 0x40A154D: GMT_free_grid_ptr (gmt_grdio.c:2023)
24725 by 0x40690A6: GMTAPI_destroy_data_ptr (gmt_api.c:1764)
24725 by 0x406E474: GMT_Garbage_Collection (gmt_api.c:3209)
24725 by 0x413BFD1: GMT_end_module (gmt_init.c:6449)
24725 by 0x422826F: GMT_grdpaste (grdpaste.c:502)
24725 by 0x407B808: GMT_Call_Module (gmt_api.c:5979)
24725 by 0x8048BE2: main (gmt.c:178)
24725 Address 0xe4af060 is 0 bytes inside a block of size 288,072,004 free'd
24725 at 0x4029DA8: free (vg_replace_malloc.c:468)
24725 by 0x50080CA: fftwf_kernel_free (in /usr/lib/i386-linux-gnu/libfftw3f.so.3.3.2)
24725 by 0x50AECAA: fftwf_free (in /usr/lib/i386-linux-gnu/libfftw3f.so.3.3.2)
24725 by 0x40BDE94: GMT_free_func (gmt_memory.c:585)
24725 by 0x40A154D: GMT_free_grid_ptr (gmt_grdio.c:2023)
24725 by 0x40690A6: GMTAPI_destroy_data_ptr (gmt_api.c:1764)
24725 by 0x406E474: GMT_Garbage_Collection (gmt_api.c:3209)
24725 by 0x413BFD1: GMT_end_module (gmt_init.c:6449)
24725 by 0x422826F: GMT_grdpaste (grdpaste.c:502)
24725 by 0x407B808: GMT_Call_Module (gmt_api.c:5979)
24725 by 0x8048BE2: main (gmt.c:178)
24725
24725
24725 HEAP SUMMARY:
24725 in use at exit: 84 bytes in 3 blocks
24725 total heap usage: 31,788 allocs, 31,787 frees, 436,601,101 bytes allocated
24725
24725 LEAK SUMMARY:
24725 definitely lost: 0 bytes in 0 blocks
24725 indirectly lost: 0 bytes in 0 blocks
24725 possibly lost: 0 bytes in 0 blocks
24725 still reachable: 84 bytes in 3 blocks
24725 suppressed: 0 bytes in 0 blocks
24725 Rerun with --leak-check=full to see details of leaked memory
24725
24725 For counts of detected and suppressed errors, rerun with: -v
24725 ERROR SUMMARY: 2 errors from 1 contexts (suppressed: 0 from 0)

You can get the files from:
http://srtm.csi.cgiar.org/SRT-ZIP/SRTM_V41/SRTM_Data_GeoTiff/srtm_22_21.zip
http://srtm.csi.cgiar.org/SRT-ZIP/SRTM_V41/SRTM_Data_GeoTiff/srtm_23_21.zip

History

#1 Updated by Joaquim over 3 years ago

Right, it should obvious not crash but again, look a those limits

grdinfo srtm_22_21.tif
srtm_22_21.tif: Title: Grid imported via GDAL
srtm_22_21.tif: Command:
srtm_22_21.tif: Remark:
srtm_22_21.tif: Gridline node registration used [Cartesian grid]
srtm_22_21.tif: Grid file format: gd = Import/export through GDAL
srtm_22_21.tif: x_min: -74.9999998547 x_max: -69.9999998547 x_inc: 0.000833333333333 name: x nx: 6001
srtm_22_21.tif: y_min: -44.9999997579 y_max: -39.9999997579 y_inc: 0.000833333333333 name: y ny: 6001

when we know for sure that they should be -75.0000000000000000, ...

#2 Updated by Paul over 3 years ago

  • Status changed from New to Feedback

How about letting grdedit loose on these before pasting?

#3 Updated by Joaquim over 3 years ago

This is again the same shitstory

grdinfo srtm_22_21.tif  (GRID A)
...
x_min: -74.9999998547 x_max: -69.9999998547

grdinfo srtm_23_21.tif  (GRID B)
...
x_min: -69.9999997337 x_max: -64.9999997337

and because x_min(A) != x_max(B) while they should be equal, the condition at line 249 of grdpaste.c

else if (fabs (A->header->wesn[XHI] - B->header->wesn[XLO]) < x_noise) {    /* A is on the left of B */

fails to evaluate to true because fabs(-69.9999998547 - -69.9999997337) = 1.20999999353444e-07 which is larger than x_noise (== 8.3333333333333338e-008)

and later 'way' becomes = 43, that translates to:

/* A is on left of B but their grid reg limits underlap by one cell */

The end result is that the array size is wrongly determined which later causes the error

Error returned from GMT API: GMT_GRID_READ_ERROR (18)

We could relax the x_noise estimation that is

x_noise = GMT_SMALL * C->header->inc[GMT_X];

but those CGIAR grids have a high screwing capacity and would strike again.

Don't know how we should fix this.

#4 Updated by Paul over 3 years ago

Might not be so bad to relax that x_noise setting a bit. 0.0001 * dx is pretty small, and when dx is as small as it is here then we are pushing into noise land anyway. Going to 0.001 would still be a pretty tight check (1 per mille).

#5 Updated by Joaquim over 3 years ago

OK, I relaxed them by one order of magnitude but we are still close to their noise level so this issue may bite again.

#6 Updated by Joaquim over 3 years ago

  • Status changed from Feedback to Resolved

#7 Updated by Paul over 3 years ago

  • Status changed from Resolved to Closed

Closing this one for now.

Also available in: Atom PDF