Opened 17 years ago

Last modified 17 years ago

#1481 closed defect (fixed)

NG Swig Dataset ReadRaster() problems

Reported by: warmerdam Owned by: warmerdam
Priority: normal Milestone: 1.4.1
Component: PythonBindings Version: 1.4.0
Severity: major Keywords:
Cc:

Description (last modified by hobu)

Reading rasters with Dataset.ReadRaster() with a multi-band band list 
results in a crash due to improperly computing buf_size (failing to
multiple by band count).

Index: Dataset.i
===================================================================
--- Dataset.i	(revision 10773)
+++ Dataset.i	(working copy)
@@ -90,9 +90,7 @@
                             int *buf_size, char **buf,
                             int band_list, int *pband_list )
 {
-
-    
-  *buf_size = buf_xsize * buf_ysize * GDALGetDataTypeSize( buf_type ) / 8;
+  *buf_size = buf_xsize * buf_ysize * (GDALGetDataTypeSize( buf_type ) / 8) * band_list;
   *buf = (char*) malloc( *buf_size );
 
   CPLErr result = GDALDatasetRasterIO(obj, GF_Read, xoff, yoff, xsize, ysize,

Change History (4)

comment:1 by warmerdam, 17 years ago

On a vaguely related note, the buf_type selection in gdal_python.i's ReadRaster 
is also wrong.  Need this patch:

Index: gdal_python.i
===================================================================
--- gdal_python.i	(revision 10773)
+++ gdal_python.i	(working copy)
@@ -185,7 +185,7 @@
             buf_ysize = ysize;
 
         if buf_type is None:
-            buf_type = self.GetRasterBand(0).DataType;
+            buf_type = self.GetRasterBand(1).DataType;
         return _gdal.Dataset_ReadRaster(self, xoff, yoff, xsize, ysize,
                                            buf_xsize, buf_ysize, buf_type,
                                            band_list)

comment:2 by warmerdam, 17 years ago

Patches applied in trunk (r10774) and gdal-1.4.x branch (r10775). 

Bindings not regenerated.

No test suite items added. 

comment:3 by warmerdam, 17 years ago

In the same vein, the WriteRaster buf_type defaulting logic was
wrong:

warmerda@amd64[260]% svn diff gdal_python.i 
Index: gdal_python.i
===================================================================
--- gdal_python.i       (revision 10774)
+++ gdal_python.i       (working copy)
@@ -163,7 +163,7 @@
         if band_list is None:
             band_list = range(1,self.RasterCount+1)
         if buf_type is None:
-            buf_type = self._band[band_list[0]-1].DataType;
+            buf_type = self.GetRasterBand(1).DataType
 
         if len(buf_string) < buf_xsize * buf_ysize * len(band_list) \
            * (_gdal.GetDataTypeSize(buf_type) / 8):


Patch applied in trunk and 1.4 branch.

comment:5 by hobu, 17 years ago

Description: modified (diff)
Milestone: 1.4.1
Note: See TracTickets for help on using tickets.