Workaround for GDAL ticket 5170, fixes #8356