Commit ac91043a authored by Daniel Scheffler's avatar Daniel Scheffler

Fixed insufficient input validation in GeoArray.

updated __version__ and __versionalias__
parent 3462bf4a
......@@ -2,8 +2,8 @@
__author__ = """Daniel Scheffler"""
__email__ = 'danschef@gfz-potsdam.de'
__version__ = '0.2.2'
__versionalias__ = 'v20170529.03'
__version__ = '0.2.3'
__versionalias__ = 'v20170529.04'
from .baseclasses import GeoArray
......
......@@ -661,6 +661,9 @@ class GeoArray(object):
if not self._gdalDataset_meta_already_set:
assert self.filePath
ds = gdal.Open(self.filePath)
if not ds:
raise Exception('Error reading file: ' + gdal.GetLastErrorMsg())
# set private class variables (in order to avoid recursion error)
self._shape = tuple([ds.RasterYSize, ds.RasterXSize] + ([ds.RasterCount] if ds.RasterCount>1 else []))
self._dtype = gdal_array.GDALTypeCodeToNumericTypeCode(ds.GetRasterBand(1).DataType)
......@@ -691,7 +694,10 @@ class GeoArray(object):
"""
ds = gdal.Open(path)
if not ds: raise IOError('Error reading image data at %s.' %path)
if not ds:
raise Exception('Error reading file: ' + gdal.GetLastErrorMsg())
R, C, B = ds.RasterYSize, ds.RasterXSize, ds.RasterCount
ds = None
......@@ -764,7 +770,7 @@ class GeoArray(object):
# check if the requested array position is already in cache -> if yes, return it from there
if self._arr_cache is not None and self._arr_cache['pos']==arr_pos:
out_arr = self._arr_cache['arr_cached']
out_arr = self._arr_cache['arr_cached']
else:
# TODO insert a multiprocessing.Lock here in order to prevent IO bottlenecks?
......@@ -776,8 +782,6 @@ class GeoArray(object):
out_arr = np.swapaxes(np.swapaxes(tempArr, 0, 2), 0, 1) if B > 1 else tempArr
else:
ds = gdal.Open(path)
if ds is None:
raise Exception('Error reading file: ' + gdal.GetLastErrorMsg())
if len(bL) == 1:
band = ds.GetRasterBand(bL[0] + 1)
out_arr= band.ReadAsArray(cS, rS, cE - cS + 1, rE - rS + 1)
......@@ -848,6 +852,9 @@ class GeoArray(object):
else:
src_ds = gdal.Open(self.filePath)
if not src_ds:
raise Exception('Error reading file: ' + gdal.GetLastErrorMsg())
gdal_Translate = get_gdal_func('Translate')
gdal_Translate(out_path, src_ds, format=fmt, creationOptions=creationOptions)
src_ds = None
......
......@@ -20,7 +20,7 @@ test_requirements = [
setup(
name='geoarray',
version='0.2.2',
version='0.2.3',
description="Fast Python interface for geodata - either on disk or in memory.",
long_description=readme + '\n\n' + history,
author="Daniel Scheffler",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment