geotrellis / gdal-warp-bindings

Thread-safe bindings for GDAL's Warp functionality
Apache License 2.0
17 stars 6 forks source link

SIGSEGV On MacOS #51

Closed metasim closed 5 years ago

metasim commented 5 years ago

Reproduce

Clone s22s/rasterframes, branch feature/gdal-warp-upgrade.

Or https://github.com/s22s/rasterframes/tree/feature/gdal-warp-upgrade

Then run:

sbt core/it:testOnly org.locationtech.rasterframes.ref.RasterSourceIT

Result

Stop of stack

Stack: [0x0000700004127000,0x0000700004227000],  sp=0x00007000042231a0,  free space=1008k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [libgdal.20.dylib+0x8f4aad]  GDAL_LercNS::BitMask::CountValidBits() const+0x29
C  [libgdal.20.dylib+0x16a2ca]  GDAL_MRF::LERC_Band::Decompress(GDAL_MRF::buf_mgr&, GDAL_MRF::buf_mgr&)+0x39a
C  [libgdal.20.dylib+0x33c394]  GDAL_MRF::GDALMRFRasterBand::IReadBlock(int, int, void*)+0x47c
C  [libgdal.20.dylib+0x4df5d1]  GDALRasterBand::GetLockedBlockRef(int, int, int)+0x175
C  [libgdal.20.dylib+0x4f3254]  GDALRasterBand::IRasterIO(GDALRWFlag, int, int, int, int, void*, int, int, GDALDataType, long long, long long, GDALRasterIOExtraArg*)+0x8ac
C  [libgdal.20.dylib+0x4de979]  GDALRasterBand::RasterIO(GDALRWFlag, int, int, int, int, void*, int, int, GDALDataType, long long, long long, GDALRasterIOExtraArg*)+0x2c1
C  [libgdal.20.dylib+0x10d53b]  GDALWarpOperation::WarpRegionToBuffer(int, int, int, int, void*, GDALDataType, int, int, int, int, double, double, double, double)+0x2bb
C  [libgdal.20.dylib+0x10e1f8]  GDALWarpOperation::WarpRegionToBuffer(int, int, int, int, void*, GDALDataType, int, int, int, int, double, double)+0x3a
C  [libgdal.20.dylib+0x457fe2]  VRTWarpedDataset::ProcessBlock(int, int)+0xe2
C  [libgdal.20.dylib+0x4583bb]  VRTWarpedRasterBand::IReadBlock(int, int, void*)+0x39
C  [libgdal.20.dylib+0x4df5d1]  GDALRasterBand::GetLockedBlockRef(int, int, int)+0x175
C  [libgdal.20.dylib+0x4e4aab]  GDALRasterBand::ComputeRasterMinMax(int, double*)+0x4dd
C  [libgdalwarp_bindings.dylib+0x96ea]  locked_dataset::get_band_max_min(int, int, int, double*, int*)+0x7a
C  [libgdalwarp_bindings.dylib+0x949f]  get_band_min_max+0x54f
C  [libgdalwarp_bindings.dylib+0x1ec8]  Java_com_azavea_gdal_GDALWarp_get_1band_1min_1max+0xb8
J 3811  com.azavea.gdal.GDALWarp.get_band_min_max(JIIIZ[D[I)I (0 bytes) @ 0x000000010a0afc77 [0x000000010a0afb80+0xf7]
J 3807 C1 geotrellis.contrib.vlm.gdal.GDALDataset$.cellType$extension1(JI)Lgeotrellis/raster/DataType; (192 bytes) @ 0x000000010a0b31b4 [0x000000010a0b2500+0xcb4]
j  geotrellis.contrib.vlm.gdal.GDALDataset$.cellType$extension0(J)Lgeotrellis/raster/DataType;+3
j  geotrellis.contrib.vlm.gdal.GDALBaseRasterSource$$anonfun$cellType$1.apply()Lgeotrellis/raster/DataType;+12
j  geotrellis.contrib.vlm.gdal.GDALBaseRasterSource$$anonfun$cellType$1.apply()Ljava/lang/Object;+1
j  scala.Option.getOrElse(Lscala/Function0;)Ljava/lang/Object;+8
j  geotrellis.contrib.vlm.gdal.GDALBaseRasterSource$class.cellType(Lgeotrellis/contrib/vlm/gdal/GDALBaseRasterSource;)Lgeotrellis/raster/DataType;+14
j  geotrellis.contrib.vlm.gdal.GDALRasterSource.cellType$lzycompute()Lgeotrellis/raster/DataType;+17
j  geotrellis.contrib.vlm.gdal.GDALRasterSource.cellType()Lgeotrellis/raster/DataType;+12

Full report: hs_err_pid38339.log.zip

Environment

GDAL

$ /usr/local/bin/gdal-config --version
2.4.1
$ /usr/local/bin/gdalinfo --formats
Supported Formats:
  VRT -raster- (rw+v): Virtual Raster
  DERIVED -raster- (ro): Derived datasets using VRT pixel functions
  GTiff -raster- (rw+vs): GeoTIFF
  NITF -raster- (rw+vs): National Imagery Transmission Format
  RPFTOC -raster- (rovs): Raster Product Format TOC format
  ECRGTOC -raster- (rovs): ECRG TOC format
  HFA -raster- (rw+v): Erdas Imagine Images (.img)
  SAR_CEOS -raster- (rov): CEOS SAR Image
  CEOS -raster- (rov): CEOS Image
  JAXAPALSAR -raster- (rov): JAXA PALSAR Product Reader (Level 1.1/1.5)
  GFF -raster- (rov): Ground-based SAR Applications Testbed File Format (.gff)
  ELAS -raster- (rw+v): ELAS
  AIG -raster- (rov): Arc/Info Binary Grid
  AAIGrid -raster- (rwv): Arc/Info ASCII Grid
  GRASSASCIIGrid -raster- (rov): GRASS ASCII Grid
  SDTS -raster- (rov): SDTS Raster
  DTED -raster- (rwv): DTED Elevation Raster
  PNG -raster- (rwv): Portable Network Graphics
  JPEG -raster- (rwv): JPEG JFIF
  MEM -raster- (rw+): In Memory Raster
  JDEM -raster- (rov): Japanese DEM (.mem)
  GIF -raster- (rwv): Graphics Interchange Format (.gif)
  BIGGIF -raster- (rov): Graphics Interchange Format (.gif)
  ESAT -raster- (rov): Envisat Image Format
  FITS -raster- (rw+): Flexible Image Transport System
  BSB -raster- (rov): Maptech BSB Nautical Charts
  XPM -raster- (rwv): X11 PixMap Format
  BMP -raster- (rw+v): MS Windows Device Independent Bitmap
  DIMAP -raster- (rov): SPOT DIMAP
  AirSAR -raster- (rov): AirSAR Polarimetric Image
  RS2 -raster- (rovs): RadarSat 2 XML Product
  SAFE -raster- (rov): Sentinel-1 SAR SAFE Product
  PCIDSK -raster,vector- (rw+v): PCIDSK Database File
  PCRaster -raster- (rw+): PCRaster Raster File
  ILWIS -raster- (rw+v): ILWIS Raster Map
  SGI -raster- (rw+v): SGI Image File Format 1.0
  SRTMHGT -raster- (rwv): SRTMHGT File Format
  Leveller -raster- (rw+v): Leveller heightfield
  Terragen -raster- (rw+v): Terragen heightfield
  GMT -raster- (rw): GMT NetCDF Grid Format
  netCDF -raster,vector- (rw+s): Network Common Data Format
  HDF4 -raster- (ros): Hierarchical Data Format Release 4
  HDF4Image -raster- (rw+): HDF4 Dataset
  ISIS3 -raster- (rw+v): USGS Astrogeology ISIS cube (Version 3)
  ISIS2 -raster- (rw+v): USGS Astrogeology ISIS cube (Version 2)
  PDS -raster- (rov): NASA Planetary Data System
  PDS4 -raster- (rw+vs): NASA Planetary Data System 4
  VICAR -raster- (rov): MIPL VICAR file
  TIL -raster- (rov): EarthWatch .TIL
  ERS -raster- (rw+v): ERMapper .ers Labelled
  JP2OpenJPEG -raster,vector- (rwv): JPEG-2000 driver based on OpenJPEG library
  L1B -raster- (rovs): NOAA Polar Orbiter Level 1b Data Set
  FIT -raster- (rwv): FIT Image
  GRIB -raster- (rwv): GRIdded Binary (.grb, .grb2)
  JPEG2000 -raster,vector- (rwv): JPEG-2000 part 1 (ISO/IEC 15444-1), based on Jasper library
  RMF -raster- (rw+v): Raster Matrix Format
  WCS -raster- (rovs): OGC Web Coverage Service
  WMS -raster- (rwvs): OGC Web Map Service
  MSGN -raster- (rov): EUMETSAT Archive native (.nat)
  RST -raster- (rw+v): Idrisi Raster A.1
  INGR -raster- (rw+v): Intergraph Raster
  GSAG -raster- (rwv): Golden Software ASCII Grid (.grd)
  GSBG -raster- (rw+v): Golden Software Binary Grid (.grd)
  GS7BG -raster- (rw+v): Golden Software 7 Binary Grid (.grd)
  COSAR -raster- (rov): COSAR Annotated Binary Matrix (TerraSAR-X)
  TSX -raster- (rov): TerraSAR-X Product
  COASP -raster- (ro): DRDC COASP SAR Processor Raster
  R -raster- (rwv): R Object Data Store
  MAP -raster- (rov): OziExplorer .MAP
  KMLSUPEROVERLAY -raster- (rwv): Kml Super Overlay
  WEBP -raster- (rwv): WEBP
  Rasterlite -raster- (rwvs): Rasterlite
  MBTiles -raster,vector- (rw+v): MBTiles
  PLMOSAIC -raster- (ro): Planet Labs Mosaics API
  CALS -raster- (rwv): CALS (Type 1)
  WMTS -raster- (rwv): OGC Web Map Tile Service
  SENTINEL2 -raster- (rovs): Sentinel 2
  MRF -raster- (rw+v): Meta Raster Format
  PNM -raster- (rw+v): Portable Pixmap Format (netpbm)
  DOQ1 -raster- (rov): USGS DOQ (Old Style)
  DOQ2 -raster- (rov): USGS DOQ (New Style)
  PAux -raster- (rw+v): PCI .aux Labelled
  MFF -raster- (rw+v): Vexcel MFF Raster
  MFF2 -raster- (rw+): Vexcel MFF2 (HKV) Raster
  FujiBAS -raster- (rov): Fuji BAS Scanner Image
  GSC -raster- (rov): GSC Geogrid
  FAST -raster- (rov): EOSAT FAST Format
  BT -raster- (rw+v): VTP .bt (Binary Terrain) 1.3 Format
  LAN -raster- (rw+v): Erdas .LAN/.GIS
  CPG -raster- (rov): Convair PolGASP
  IDA -raster- (rw+v): Image Data and Analysis
  NDF -raster- (rov): NLAPS Data Format
  EIR -raster- (rov): Erdas Imagine Raw
  DIPEx -raster- (rov): DIPEx
  LCP -raster- (rwv): FARSITE v.4 Landscape File (.lcp)
  GTX -raster- (rw+v): NOAA Vertical Datum .GTX
  LOSLAS -raster- (rov): NADCON .los/.las Datum Grid Shift
  NTv1 -raster- (rov): NTv1 Datum Grid Shift
  NTv2 -raster- (rw+vs): NTv2 Datum Grid Shift
  CTable2 -raster- (rw+v): CTable2 Datum Grid Shift
  ACE2 -raster- (rov): ACE2
  SNODAS -raster- (rov): Snow Data Assimilation System
  KRO -raster- (rw+v): KOLOR Raw
  ROI_PAC -raster- (rw+v): ROI_PAC raster
  RRASTER -raster- (rw+v): R Raster
  BYN -raster- (rw+v): Natural Resources Canada's Geoid
  ARG -raster- (rwv): Azavea Raster Grid format
  RIK -raster- (rov): Swedish Grid RIK (.rik)
  USGSDEM -raster- (rwv): USGS Optional ASCII DEM (and CDED)
  GXF -raster- (rov): GeoSoft Grid Exchange Format
  DODS -raster- (ro): DAP 3.x servers
  BAG -raster- (rwv): Bathymetry Attributed Grid
  HDF5 -raster- (rovs): Hierarchical Data Format Release 5
  HDF5Image -raster- (rov): HDF5 Dataset
  NWT_GRD -raster- (rw+v): Northwood Numeric Grid Format .grd/.tab
  NWT_GRC -raster- (rov): Northwood Classified Grid Format .grc/.tab
  ADRG -raster- (rw+vs): ARC Digitized Raster Graphics
  SRP -raster- (rovs): Standard Raster Product (ASRP/USRP)
  BLX -raster- (rwv): Magellan topo (.blx)
  EPSILON -raster- (rwv): Epsilon wavelets
  PostGISRaster -raster- (rws): PostGIS Raster driver
  SAGA -raster- (rw+v): SAGA GIS Binary Grid (.sdat, .sg-grd-z)
  XYZ -raster- (rwv): ASCII Gridded XYZ
  HF2 -raster- (rwv): HF2/HFZ heightfield raster
  OZI -raster- (rov): OziExplorer Image File
  CTG -raster- (rov): USGS LULC Composite Theme Grid
  E00GRID -raster- (rov): Arc/Info Export E00 GRID
  ZMap -raster- (rwv): ZMap Plus Grid
  NGSGEOID -raster- (rov): NOAA NGS Geoid Height Grids
  IRIS -raster- (rov): IRIS data (.PPI, .CAPPi etc)
  PRF -raster- (rov): Racurs PHOTOMOD PRF
  RDA -raster- (ro): DigitalGlobe Raster Data Access driver
  EEDAI -raster- (ros): Earth Engine Data API Image
  SIGDEM -raster- (rwv): Scaled Integer Gridded DEM .sigdem
  IGNFHeightASCIIGrid -raster- (rov): IGN France height correction ASCII Grid
  GPKG -raster,vector- (rw+vs): GeoPackage
  CAD -raster,vector- (rovs): AutoCAD Driver
  PLSCENES -raster,vector- (ro): Planet Labs Scenes API
  NGW -raster,vector- (rw+s): NextGIS Web
  GenBin -raster- (rov): Generic Binary (.hdr Labelled)
  ENVI -raster- (rw+v): ENVI .hdr Labelled
  EHdr -raster- (rw+v): ESRI .hdr Labelled
  ISCE -raster- (rw+v): ISCE raster
  HTTP -raster,vector- (ro): HTTP Fetching Wrapper

Machine

MacOS 10.13.6 (17G6030)
Darwin DongleBookPro.s22s.net 17.7.0 Darwin Kernel Version 17.7.0: Wed Feb 27 00:43:23 PST 2019; root:xnu-4570.71.35~1/RELEASE_X86_64 x86_64

JVM

openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-2~deb9u1-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)

Libraries

metasim commented 5 years ago

NB: Does not happen on Linux.

pomadchin commented 5 years ago

I will try to reproduce it on my machine:

metasim commented 5 years ago

I think it's happening in the JPEG2000 test. Actually, from the backtrace it looks like the MRF test.

metasim commented 5 years ago

More version info:

$ brew info osgeo-gdal
osgeo/osgeo4mac/osgeo-gdal: stable 2.4.1 (bottled), HEAD
GDAL: Geospatial Data Abstraction Library
https://www.gdal.org/
/usr/local/Cellar/osgeo-gdal/2.4.1_1 (198 files, 55.9MB) *
  Poured from bottle on 2019-03-29 at 13:55:12
From: https://github.com/osgeo/homebrew-osgeo4mac/blob/master/Formula/osgeo-gdal.rb
==> Dependencies
Required: pkg-config ✔, libiconv ✘, expat ✔, zlib ✔, qhull ✔, curl-openssl ✘, libpng ✘, freexl ✔, geos ✘, jpeg-turbo ✘, json-c ✔, giflib ✔, libpq ✘, sqlite ✘, pcre ✔, libtiff ✔, numpy ✘, armadillo ✘, sfcgal ✘, ant ✘, swig ✘, mdbtools ✔, libzip ✔, openssl ✔, cryptopp ✔, osgeo-libgeotiff ✘, osgeo-libspatialite ✘, osgeo-libkml ✔, osgeo-netcdf ✘, osgeo-hdf4 ✔, hdf5 ✘, cfitsio ✔, epsilon ✔, jasper ✔, libdap ✘, libxml2 ✔, openjpeg ✘, zstd ✘, webp ✔, unixodbc ✔, xerces-c ✔, xz ✔, osgeo-proj ✘, osgeo-postgresql ✘

$ brew info openjpeg
openjpeg: stable 2.3.1 (bottled), HEAD
Library for JPEG-2000 image manipulation
jamesmcclain commented 5 years ago

Preliminarily, this looks like it may be an issue related to the MRF driver. The stack trace shows execution passing through libgdalwarp_bindings.dylib and through the core of GDAL, then into the MRF driver where it encounters a problem.

In order to investigate further, it might help us to have a core file if we are not able to reproduce the problem. Or better yet, since I will not be able to match your environment exactly, a walk through the stack in a debugger as described here would be envaluable. Without that, I will not be able to investigate this until after work (because my MacOS installation is on my personal computer).

I am especially interested to see what the parameters were to the first function in the core of GDAL called by libgdalwarp_bindings.dylib: it should be easy to see whether they look "normal", and if so to create a small program to attempt to isolate the issue.

jamesmcclain commented 5 years ago

@metasim I was not able to reproduce (please check the top left of the screenshot to ensure that I typed the correct command to launch the tests [I did so without the single quotes around the last two arguments and got the same result]).

Screenshot_2019-07-03_10-23-29

I did noticed that I have a different version of GDAL than you do: mine responds to the command brew info gdal whereas yours responds to brew info osgeo-gdal. If those are in fact different builds, that might account for different behavior.

metasim commented 5 years ago

I didn't realize the non osgeo gdal would work. I'll uninstall the osgeo one and try things out. Thanks for hunting down that difference.

jamesmcclain commented 5 years ago

I didn't realize the non osgeo gdal would work. I'll uninstall the osgeo one and try things out. Thanks for hunting down that difference.

No problem, my fingers are crossed!

metasim commented 5 years ago

:( Still getting the crash. I'm inclined to close it because it appears to be unique to me. I can provide a core file if it's helpful. Here's what I came up with:

(lldb) thread backtrace
* thread #25, stop reason = signal SIGSTOP
    frame #0: 0x00007fff673ddb66 libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007fff675a8080 libsystem_pthread.dylib`pthread_kill + 333
    frame #2: 0x00007fff673391ae libsystem_c.dylib`abort + 127
    frame #3: 0x000000010628cc3f libjvm.dylib`os::abort(bool) + 25
    frame #4: 0x00000001063b4e26 libjvm.dylib`VMError::report_and_die() + 2304
    frame #5: 0x000000010628e882 libjvm.dylib`JVM_handle_bsd_signal + 1131
    frame #6: 0x000000010628aabf libjvm.dylib`signalHandler(int, __siginfo*, void*) + 47
  * frame #7: 0x00007fff6759bf5a libsystem_platform.dylib`_sigtramp + 26
    frame #8: 0x00000001235c1eee libgdal.20.dylib`GDAL_LercNS::BitMask::CountValidBits() const + 42
    frame #9: 0x0000000122e7604a libgdal.20.dylib`GDAL_MRF::LERC_Band::Decompress(GDAL_MRF::buf_mgr&, GDAL_MRF::buf_mgr&) + 922
    frame #10: 0x000000012302f914 libgdal.20.dylib`GDAL_MRF::GDALMRFRasterBand::IReadBlock(int, int, void*) + 1148
    frame #11: 0x00000001231de8f1 libgdal.20.dylib`GDALRasterBand::GetLockedBlockRef(int, int, int) + 373
    frame #12: 0x00000001231f2574 libgdal.20.dylib`GDALRasterBand::IRasterIO(GDALRWFlag, int, int, int, int, void*, int, int, GDALDataType, long long, long long, GDALRasterIOExtraArg*) + 2220
    frame #13: 0x00000001231ddc99 libgdal.20.dylib`GDALRasterBand::RasterIO(GDALRWFlag, int, int, int, int, void*, int, int, GDALDataType, long long, long long, GDALRasterIOExtraArg*) + 705
    frame #14: 0x0000000122e2a6eb libgdal.20.dylib`GDALWarpOperation::WarpRegionToBuffer(int, int, int, int, void*, GDALDataType, int, int, int, int, double, double, double, double) + 699
    frame #15: 0x0000000122e2b3a8 libgdal.20.dylib`GDALWarpOperation::WarpRegionToBuffer(int, int, int, int, void*, GDALDataType, int, int, int, int, double, double) + 58
    frame #16: 0x00000001231572c2 libgdal.20.dylib`VRTWarpedDataset::ProcessBlock(int, int) + 226
    frame #17: 0x000000012315769b libgdal.20.dylib`VRTWarpedRasterBand::IReadBlock(int, int, void*) + 57
    frame #18: 0x00000001231de8f1 libgdal.20.dylib`GDALRasterBand::GetLockedBlockRef(int, int, int) + 373
    frame #19: 0x00000001231e3dcb libgdal.20.dylib`GDALRasterBand::ComputeRasterMinMax(int, double*) + 1245
    frame #20: 0x00000001201396ea libgdalwarp_bindings.dylib`locked_dataset::get_band_max_min(int, int, int, double*, int*) + 122
    frame #21: 0x000000012013949f libgdalwarp_bindings.dylib`get_band_min_max + 1359
    frame #22: 0x0000000120131ec8 libgdalwarp_bindings.dylib`Java_com_azavea_gdal_GDALWarp_get_1band_1min_1max + 184
    frame #23: 0x000000010e8bd337
...

I walked up the stack some running frame variable to see if I could get the function parameters but lldb didn't report anything.

e.g.

(lldb) frame select 20
frame #20: 0x00000001201396ea libgdalwarp_bindings.dylib`locked_dataset::get_band_max_min(int, int, int, double*, int*) + 122
libgdalwarp_bindings.dylib`locked_dataset::get_band_max_min:
    0x1201396ea <+122>: movq   -0x30(%rbp), %rdx
    0x1201396ee <+126>: movl   $0x1, (%rdx)
    0x1201396f4 <+132>: jmp    0x120139736               ; <+198>
    0x1201396f9 <+137>: movq   -0x38(%rbp), %rdi
(lldb) frame variable
(lldb)

Not sure from this what other kind of core file inspection is helpful.

pomadchin commented 5 years ago

My update: I could not reproduce it on my machine :/

metasim commented 5 years ago

Thanks guys. Sorry to waste your time.

jamesmcclain commented 5 years ago

I walked up the stack some running frame variable to see if I could get the function parameters but lldb didn't report anything.

Ah, okay, that is unfortunate.

I am happy to revisit this issue later, if there is impetus.

jamesmcclain commented 5 years ago

Thanks guys. Sorry to waste your time.

No problem! I appreciate the engagement!