Skip to content

nil dereference in reading metadata #71

@osklyar

Description

@osklyar

In func (dataset *Dataset) Metadata(domain string) []string (gdal.go:687) when the execution reaches the end of the list it panics with nil dereference. For some reason I have observed this behavior on OSX only, but not on linux:

➜  Downloads hdf2tiff HDF4_EOS:EOS_GRID:"MYD10A1.A2008006.h19v02.006.2016142113721.hdf":MOD_Grid_Snow_500m:NDSI_Snow_Cover foo.tiff
unexpected fault address 0xb01dfacedebac1e
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x1 addr=0xb01dfacedebac1e pc=0x4005d6e]

goroutine 1 [running]:
runtime.throw(0x40ecae4, 0x5)
	/usr/local/go/src/runtime/panic.go:1117 +0x72 fp=0xc0000b3af0 sp=0xc0000b3ac0 pc=0x40370d2
runtime.sigpanic()
	/usr/local/go/src/runtime/signal_unix.go:741 +0x276 fp=0xc0000b3b28 sp=0xc0000b3af0 pc=0x404bf36
indexbytebody(0x554c4f4341544144, 0xebc, 0x0, 0xc0000b3b78, 0xebc, 0x0, 0x554c4f4341544144, 0x554c4f4341544144, 0xebc, 0xc0000b3bd0, ...)
	/usr/local/go/src/internal/bytealg/indexbyte_amd64.s:124 +0xce fp=0xc0000b3b30 sp=0xc0000b3b28 pc=0x4005d6e
runtime.findnull(0x554c4f4341544144, 0x0)
	/usr/local/go/src/runtime/string.go:438 +0x87 fp=0xc0000b3b88 sp=0xc0000b3b30 pc=0x4051d27
runtime.gostring(0x554c4f4341544144, 0x0, 0x0)
	/usr/local/go/src/runtime/string.go:320 +0x2f fp=0xc0000b3be0 sp=0xc0000b3b88 pc=0x4065daf
github.com/lukeroth/gdal._Cfunc_GoString(...)
	_cgo_gotypes.go:3002
github.com/lukeroth/gdal.(*Dataset).Metadata(0xc0000b3d88, 0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/osklyar/Library/Go/pkg/mod/github.com/osklyar/gdal@v0.0.0-20210506223057-2fecd07bf2d8/gdal.go:687 +0x109 fp=0xc0000b3c78 sp=0xc0000b3be0 pc=0x40b3929
github.com/nordicsense/modis/dataset.Open(0x7ffeefbffaf9, 0x62, 0x40eb200, 0xc00008c101, 0xc000082480, 0xc0000486c0)
	/Users/osklyar/Library/Go/pkg/mod/github.com/nordicsense/modis@v0.0.0-20210509214422-ca11fe4bf0d6/dataset/file.go:46 +0x45e fp=0xc0000b3e58 sp=0xc0000b3c78 pc=0x40b833e
main.convert(0x7ffeefbffaf9, 0x62, 0x7ffeefbffb5c, 0x8, 0x0, 0x0)
	/Users/osklyar/src/github.com/nordicsense/lstproxy/hdf2tiff/hdf2tiff.go:18 +0x70 fp=0xc0000b3f38 sp=0xc0000b3e58 pc=0x40ba150
main.main()
	/Users/osklyar/src/github.com/nordicsense/lstproxy/hdf2tiff/hdf2tiff.go:12 +0x67 fp=0xc0000b3f88 sp=0xc0000b3f38 pc=0x40ba067
runtime.main()
	/usr/local/go/src/runtime/proc.go:225 +0x256 fp=0xc0000b3fe0 sp=0xc0000b3f88 pc=0x40398f6
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:1371 +0x1 fp=0xc0000b3fe8 sp=0xc0000b3fe0 pc=0x4068e61

The patch #70 is ready and tested and I will submit a PR separately. It should work equally on linux as it only adds another nil check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions