#166: short integer overflow with r.in.gdal
---------------------+------------------------------------------------------
Reporter: dylan | Owner: grass-dev@lists.osgeo.org
Type: defect | Status: new
Priority: major | Milestone: 6.4.0
Component: default | Version: unspecified
Keywords: |
---------------------+------------------------------------------------------
Noticed that importing Arc ASCII grid files with r.in.gdal can lead to
data corruption when the input file contains integer values larger than
what can be stored in a short integer (>32767). See the test case and
attached file below.
test case:
{{{
# setup in spearfish60 location
g.region res=1000 -pa
# make a map with values larger than what a short integer can hold
r.mapcalc "large_int_map = rand(10000, 78000)"
# export to Arc ASCII format
r.out.arc in=large_int_map out=big_int_arc_file.asc
# import with GDAL:
r.in.gdal -o in=big_int_arc_file.asc out=big_int_arc_file
# we are stuck with short integer values and data corruption:
r.info big_int_arc_file -r
min=-31293
max=32420
}}}
It looks like the culprit may be associated with the following lines from
the r.out.gdal source (main.c:677 | revision 31323):
{{{
/* -------------------------------------------------------------------- */
/* Select a cell type for the new cell. */
/* -------------------------------------------------------------------- */
eRawGDT = GDALGetRasterDataType( hBand );
switch(eRawGDT) {
case GDT_Float32:
case GDT_Float64:
data_type = FCELL_TYPE;
eGDT = GDT_Float32;
complex = FALSE;
break;
#166: short integer overflow with r.in.gdal
----------------------+-----------------------------------------------------
Reporter: dylan | Owner: grass-dev@lists.osgeo.org
Type: defect | Status: new
Priority: major | Milestone: 6.4.0
Component: default | Version: svn-trunk
Resolution: | Keywords: gdal
----------------------+-----------------------------------------------------
Changes (by dylan):
* keywords: gdal r.in.gdal => gdal
Comment:
This appears to be a problem with GDAL not recognizing the ASCII grid data
type, as GDAL-specific operations such as gdal_translate produce erroneous
results. GDAL is interpreting the attached input file as Int16.
#166: short integer overflow with r.in.gdal
----------------------+-----------------------------------------------------
Reporter: dylan | Owner: grass-dev@lists.osgeo.org
Type: task | Status: new
Priority: major | Milestone: 6.4.0
Component: default | Version: svn-trunk
Resolution: | Keywords: gdal
----------------------+-----------------------------------------------------
Changes (by dylan):
* type: defect => task
Comment:
Since this is a GDAL bug, I will change the type to "task", and make a new
ticket on the GDAL tracker. The fix for now is to use r.in.arc for any AA
Grid files which contain large (32bit) integer data.
#166: short integer overflow with r.in.gdal
----------------------+-----------------------------------------------------
Reporter: dylan | Owner: grass-dev@lists.osgeo.org
Type: task | Status: new
Priority: major | Milestone: 6.4.0
Component: default | Version: svn-trunk
Resolution: | Keywords: gdal
----------------------+-----------------------------------------------------
Comment (by dylan):
Replying to [comment:3 dylan]:
> Since this is a GDAL bug, I will change the type to "task", and make a
new ticket on the GDAL tracker. The fix for now is to use r.in.arc for any
AA Grid files which contain large (32bit) integer data.