Centos 6.5 Final GDAL/ECW Segmentation Fault

Mithenks Source

I have an odd problem with libgdal and ECW, on centos 6.5 final. When I try to read an ECW file with gdalinfo (or anything else) I get a Segmentation fault.

It's very strange because I have many virtual machine with same centos and same ecw/gdal compiled lib, but this happens only on one of them.

Trying to debugging the error with gdb, I notice that ecw trying to allocate a string of 2147483647 characters, but on the system the limit is 1073741820.

It's possibile to tell libgdal/libecw which max_size limit for string they have to use? It's possibile to change max_size for the system?

Any ideas would be appreciated :)

OS: centos 6.5 (Final) ECW lib: libecwj2-3.3 GDAL lib: gdal 1.9.2

Error opening an ecw file with gdalinfo:

terminate called after throwing an instance of 'std::length_error'
  what():  basic_string::_S_create

gdb stack trace

#0  0x00130424 in __kernel_vsyscall ()
#1  0x00e1ab11 in raise () from /lib/libc.so.6
#2  0x00e1c3ea in abort () from /lib/libc.so.6
#3  0x00d6db87 in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/libstdc++.so.6
#4  0x00d6b9e6 in ?? () from /usr/lib/libstdc++.so.6
#5  0x00d6ba23 in std::terminate() () from /usr/lib/libstdc++.so.6
#6  0x00d6bb62 in __cxa_throw () from /usr/lib/libstdc++.so.6
#7  0x00d0c960 in std::__throw_length_error(char const*) () from /usr/lib/libstdc++.so.6
#8  0x00d48ef6 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_S_create(unsigned int, unsigned int, std::allocator<char> const&) () from /usr/lib/libstdc++.so.6
#9  0x00d4a029 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_M_clone(std::allocator<char> const&, unsigned int) () from /usr/lib/libstdc++.so.6
#10 0x00d4a578 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::reserve(unsigned int) () from /usr/lib/libstdc++.so.6
#11 0x00a699f3 in TiXmlDocument::LoadFile (this=0x80642e4, filename=0x8064374 "/root/", encoding=TIXML_ENCODING_UNKNOWN) at ../C/NCSEcw/NCSJP2/../../tinyxml/tinyxml.cpp:995
#12 0x00b4ae6b in CNCSPrefsXML::CNCSPrefsXML (this=0x8064280, sFilename=...) at ../C/NCSUtil/NCSPrefsXML.cpp:78
#13 0x00b4b0f0 in CNCSPrefsXML::Init () at ../C/NCSUtil/NCSPrefsXML.cpp:40
#14 0x00b46dd7 in NCSPrefInit () at ../C/NCSUtil/NCSPrefs.cpp:84
#15 0x00b4fcf5 in NCSUtilInit () at ../C/NCSUtil/util.c:81
#16 0x00ac5e90 in NCSecwInitInternal () at ../C/NCSEcw/NCSEcw/NCSEcw.cpp:335
#17 0x00ac6aa7 in NCSecwInit () at ../C/NCSEcw/NCSEcw/NCSEcw.cpp:355
#18 0x003321b7 in ECWInitialize () at ecwdataset.cpp:1891
#19 0x00335fa4 in ECWDataset::Open (poOpenInfo=0xbfff5540, bIsJPEG2000=0) at ecwdataset.cpp:1369
#20 0x0033652a in ECWDataset::OpenECW (poOpenInfo=0xbfff5540) at ecwdataset.cpp:1246
#21 0x00550163 in GDALOpenInternal (oOpenInfo=..., papszAllowedDrivers=0x0) at gdaldataset.cpp:2251
#22 0x0055077a in GDALOpenInternal (pszFilename=0x8063480 "/mnt/sdb1/mapguide_data/sienaprovincia/ortofoto_1954/1954.ecw", eAccess=GA_ReadOnly, papszAllowedDrivers=0x0) at gdaldataset.cpp:2209
#23 0x005507dc in GDALOpen (pszFilename=0x8063480 "/mnt/sdb1/mapguide_data/sienaprovincia/ortofoto_1954/1954.ecw", eAccess=GA_ReadOnly) at gdaldataset.cpp:2200
#24 0x08049eed in main (argc=2, argv=0x8063450) at gdalinfo.c:173


answered 4 years ago Mithenks #1

We've found where the problem is. libecw try to save a prefs file but, for a buggy code in NCSUtil, it tells tinyxml to open a directory as a file. Generally this fails but without great problems. Howewhere we are experienced a strange behaviour of ftell() function, used by tinyxml, on one system.

See: https://stackoverflow.com/questions/21307977/strange-behaviour-of-ftell-on-twin-system

This bad return value from ftell cause tinyxml trying to allocate a (2^31)-1 size string, which is bigger than system limit. So everything crashed.

If someone experienced a similar behaviour of ftell() please tell us, we're interesting in understandig what cause the different results on similar systems.

comments powered by Disqus