airbusgeo / godal

golang wrapper for github.com/OSGEO/gdal
Apache License 2.0
137 stars 27 forks source link

WarpInto: stack smashing detected #84

Closed thomascoquet closed 2 years ago

thomascoquet commented 2 years ago

Hello Thomas,

I am posting this here as I did not manage to reproduce neither with gdalwarp nor the SWIG bindings for python.

I am having a very weird behavior with custom presigned URL (and hence quite long). Here's a test to reproduce (I removed all special characters in the query part):

package godal_test

import (
    "context"
    "fmt"
    "os"
    "testing"

    "github.com/airbusgeo/godal"
    "github.com/airbusgeo/osio"
    "github.com/stretchr/testify/assert"
)

var ErrLoger = godal.ErrLogger(func(ec godal.ErrorCategory, code int, msg string) error {
    fmt.Printf("[gdal-debug] %d - %d - %s\n", ec, code, msg)
    if ec < godal.CE_Warning {
        return nil
    }
    return fmt.Errorf("gdal: code %d (%s)", code, msg)
})

func TestS5P(t *testing.T) {
    os.Setenv("CPL_DEBUG", "ON")
    ctx := context.Background()

    // drivers and adapters
    godal.RegisterRaster(godal.GTiff, godal.Memory)
    httpr, err := osio.HTTPHandle(ctx)
    assert.Nil(t, err)
    httpa, err := osio.NewAdapter(httpr)
    assert.Nil(t, err)
    godal.RegisterVSIHandler("http://", httpa)
    godal.RegisterVSIHandler("https://", httpa)

    // open and warp
    uri := "https://meeo-s5p.s3.amazonaws.com/COGT/OFFL/L2__CO____/2018/07/12/S5P_OFFL_L2__CO_____20180712T110154_20180712T124324_03860_01_010100_20180718T164726_PRODUCT_carbonmonoxide_total_column_4326.tif?xjphxjasdvfdrd=2022j03j24T14j3A43j3A53Z&jjpxjexpires=1h&xjphxjissuer=userjjjinternaljjjjjjjjjjjjjjjjcatalog&xjphxjmehods=GETjjjHEAD&xjphxjsignture=v1jvOjjjsblsIjjjNIVEm70McGBjjjmR10RCFVqKigYIoHtyxjjjJ2KKhsKRSlvUfZTvrBQ2fVgal4e0MYMA5IVJ6jjj1sNGbCgjjjjjj&xjphxjsignedjparameters=xjphxjjreatedjjjxjphxjmethodsjjjxjphxjuserjjjxjphxjexpiresjjjxjphxjdddddd&xjphxjuser=userjjjinternaljjjt.coquet"
    src, err := godal.Open(uri, ErrLoger)
    assert.Nil(t, err)
    defer src.Close()

    // create an in-memory raster
    dst, err := godal.Create(godal.Memory, "", src.Structure().NBands, src.Structure().DataType, 512, 512, ErrLoger)
    assert.Nil(t, err)
    defer dst.Close()

    sr, err := godal.NewSpatialRefFromEPSG(3857)
    assert.Nil(t, err)
    assert.Nil(t, dst.SetSpatialRef(sr))
    assert.Nil(t, dst.SetGeoTransform([6]float64{0, 1222.99245256282, 0, 5.009377085697301e+06, 0, -1222.99245256282}))

    // warping
    assert.Nil(t, dst.WarpInto([]*godal.Dataset{src}, []string{}, ErrLoger))
}

Yields:

[gdal-debug] 1 - 0 - GDAL: GDALOpen(https://meeo-s5p.s3.amazonaws.com/COGT/OFFL/L2__CO____/2018/07/12/S5P_OFFL_L2__CO_____20180712T110154_20180712T124324_03860_01_010100_20180718T164726_PRODUCT_carbonmonoxide_total_column_4326.tif?xjphxjasdvfdrd=2022j03j24T14j3A43j3A53Z&jjpxjexpires=1h&xjphxjissuer=userjjjinternaljjjjjjjjjjjjjjjjcatalog&xjphxjmehods=GETjjjHEAD&xjphxjsignture=v1jvOjjjsblsIjjjNIVEm70McGBjjjmR10RCFVqKigYIoHtyxjjjJ2KKhsKRSlvUfZTvrBQ2fVgal4e0MYMA5IVJ6jjj1sNGbCgjjjjjj&xjphxjsignedjparameters=xjphxjjreatedjjjxjphxjmethodsjjjxjphxjuserjjjxjphxjexpiresjjjxjphxjdddddd&xjphxjuser=userjjjinternaljjjt.coquet, this=0x23cf7a0) succeeds as GTiff.
[gdal-debug] 1 - 0 - GDAL: GDALDriver::Create(MEM,,512,512,1,Float32,(nil))
[gdal-debug] 1 - 0 - GDALWARP: Defining SKIP_NOSOURCE=YES
[gdal-debug] 1 - 0 - WARP: Copying metadata from first source to destination dataset
*** stack smashing detected ***: <unknown> terminated
SIGABRT: abort
PC=0x7fe074027e87 m=0 sigcode=18446744073709551610
signal arrived during cgo execution

goroutine 20 [syscall]:
runtime.cgocall(0xa558b0, 0xc000159c38)
    /home/thomascoquet/sdk/go1.18beta1/src/runtime/cgocall.go:157 +0x5c fp=0xc000159c10 sp=0xc000159bd8 pc=0x40cf5c
github.com/airbusgeo/godal._Cfunc_godalDatasetWarpInto(0x26beaf0, 0x23d0ad0, 0x1, 0xc000406030, 0x0)
    _cgo_gotypes.go:1338 +0x45 fp=0xc000159c38 sp=0xc000159c10 pc=0xa2ab85
github.com/airbusgeo/godal.(*Dataset).WarpInto.func1({0x26beaf0?, {0x0?, 0xabeae0?}}, 0x413dd5?, {0xc000159ed8?, 0x1, 0xa81a00?}, 0xc000159d30, {0x0, 0x0})
    /home/thomascoquet/Work/kayrros-godal/godal/godal.go:956 +0x105 fp=0xc000159c88 sp=0xc000159c38 pc=0xa352e5
github.com/airbusgeo/godal.(*Dataset).WarpInto(0xc000406010, {0xc000159ed8, 0x1, 0x1}, {0xc000159dd0, 0x0, 0x0}, {0xc000159f00, 0x1, 0x1})
    /home/thomascoquet/Work/kayrros-godal/godal/godal.go:956 +0x237 fp=0xc000159d78 sp=0xc000159c88 pc=0xa350b7
github.com/airbusgeo/godal_test.TestS5P(0x0?)
    /home/thomascoquet/Work/kayrros-godal/godal/s5p_test.go:52 +0x615 fp=0xc000159f70 sp=0xc000159d78 pc=0xa54535
testing.tRunner(0xc0003031e0, 0xc2bf78)
    /home/thomascoquet/sdk/go1.18beta1/src/testing/testing.go:1410 +0x102 fp=0xc000159fc0 sp=0xc000159f70 pc=0x51ae42
testing.(*T).Run.func1()
    /home/thomascoquet/sdk/go1.18beta1/src/testing/testing.go:1457 +0x2a fp=0xc000159fe0 sp=0xc000159fc0 pc=0x51bcea
runtime.goexit()
    /home/thomascoquet/sdk/go1.18beta1/src/runtime/asm_amd64.s:1571 +0x1 fp=0xc000159fe8 sp=0xc000159fe0 pc=0x472081
created by testing.(*T).Run
    /home/thomascoquet/sdk/go1.18beta1/src/testing/testing.go:1457 +0x35f

Note that if you remove the period from my user id (t.coquet -> tcoquet), the error disappears.

The following python code was used to test GDAL. I saw no error on my side:

from osgeo import gdal, ogr
gdal.UseExceptions() 

uri = "..."
src = gdal.Open(uri)
driver = gdal.GetDriverByName('MEM')
dst = driver.Create('', 512, 512, 1, gdal.GDT_Float32, [])
sr = ogr.osr.SpatialReference()
sr.ImportFromEPSG(3857)
dst.SetSpatialRef(sr)
dst.SetGeoTransform([0,1222.99245256282,0,5.009377085697301e+06,0,-1222.99245256282])
gdal.Warp(dst, src)

Any idea? Thanks


[UPDATE] gdal 3.0.4 locally, go 1.18, running on Ubuntu, latest godal version. I have the same bug using osgeo/gdal:alpine-small-3.4.2

tbonfort commented 2 years ago

probable gdal bug: OSGEO/gdal#5506