[postgis-commits] svn - r3670 - in spike/wktraster: rt_core
rt_pg/test
postgis-commits at postgis.refractions.net
postgis-commits at postgis.refractions.net
Fri Feb 6 08:58:59 PST 2009
Author: strk
Date: 2009-02-06 08:58:58 -0800 (Fri, 06 Feb 2009)
New Revision: 3670
Modified:
spike/wktraster/rt_core/rt_api.c
spike/wktraster/rt_pg/test/io.sql
spike/wktraster/rt_pg/test/io_expected
Log:
Check for out-of-range pixel values (for <8bit pixtypes) and test it
Modified: spike/wktraster/rt_core/rt_api.c
===================================================================
--- spike/wktraster/rt_core/rt_api.c 2009-02-06 13:20:48 UTC (rev 3669)
+++ spike/wktraster/rt_core/rt_api.c 2009-02-06 16:58:58 UTC (rev 3670)
@@ -1406,6 +1406,7 @@
int pixbytes;
uint8_t type;
unsigned long sz;
+ uint32_t v;
band = ctx->alloc(sizeof(struct rt_band_t));
if ( ! band )
@@ -1595,28 +1596,55 @@
/* Should now flip values if > 8bit and
* littleEndian != isMachineLittleEndian */
- if ( pixbytes > 1 && isMachineLittleEndian() != littleEndian )
+ if ( pixbytes > 1 )
+ {
+ if ( isMachineLittleEndian() != littleEndian )
+ {{
+ void (*flipper)(uint8_t*) = 0;
+ void *flipme;
+
+ if ( pixbytes == 2 ) flipper = flip_endian_16;
+ else if ( pixbytes == 4 ) flipper = flip_endian_32;
+ else if ( pixbytes == 8 ) flipper = flip_endian_64;
+ else {
+ ctx->err("Unexpected pix bytes %d", pixbytes);
+ ctx->dealloc(band);
+ ctx->dealloc(band->data.mem);
+ return 0;
+ }
+
+ flipme = band->data.mem;
+ sz = width*height;
+ for (v=0; v<sz; ++v)
+ {
+ flipper(flipme);
+ flipme += pixbytes;
+ }
+ }}
+ }
+
+ /* And should check for invalid values for < 8bit types */
+ else if ( band->pixtype == PT_1BB ||
+ band->pixtype == PT_2BUI ||
+ band->pixtype == PT_4BUI )
{{
- void (*flipper)(uint8_t*) = 0;
- void *flipme;
- uint32_t v;
+ uint8_t maxVal = band->pixtype == PT_1BB ? 1 :
+ band->pixtype == PT_2BUI ? 3 :
+ 15 ;
+ uint8_t val;
- if ( pixbytes == 2 ) flipper = flip_endian_16;
- else if ( pixbytes == 4 ) flipper = flip_endian_32;
- else if ( pixbytes == 8 ) flipper = flip_endian_64;
- else {
- ctx->err("Unexpected pix bytes %d", pixbytes);
- ctx->dealloc(band);
- ctx->dealloc(band->data.mem);
- return 0;
- }
-
- flipme = band->data.mem;
sz = width*height;
for (v=0; v<sz; ++v)
{
- flipper(flipme);
- flipme += pixbytes;
+ val = ((uint8_t*)band->data.mem)[v];
+ if ( val > maxVal )
+ {
+ ctx->err("Invalid value %d for pixel of type %s",
+ val, rt_pixtype_name(ctx, band->pixtype));
+ ctx->dealloc(band->data.mem);
+ ctx->dealloc(band);
+ return 0;
+ }
}
}}
Modified: spike/wktraster/rt_pg/test/io.sql
===================================================================
--- spike/wktraster/rt_pg/test/io.sql 2009-02-06 13:20:48 UTC (rev 3669)
+++ spike/wktraster/rt_pg/test/io.sql 2009-02-06 16:58:58 UTC (rev 3670)
@@ -866,3 +866,60 @@
hexwkb_ndr::raster::text = hexwkb_ndr or hexwkb_ndr::raster::text = hexwkb_xdr as ndr_io,
hexwkb_xdr::raster::text = hexwkb_ndr or hexwkb_xdr::raster::text = hexwkb_xdr as xdr_io
FROM rt_test;
+
+-- Out of range value for 1BB pixeltype
+SELECT (
+ '01' || -- little endian (uint8 ndr)
+ '0000' || -- version (uint16 0)
+ '0100' || -- nBands (uint16 1)
+ '000000000000F03F' || -- scaleX (float64 1)
+ '000000000000F03F' || -- scaleY (float64 1)
+ '0000000000000000' || -- ipX (float64 0)
+ '0000000000000000' || -- ipY (float64 0)
+ '0000000000000000' || -- skewX (float64 0)
+ '0000000000000000' || -- skewY (float64 0)
+ '0A000000' || -- SRID (int32 10)
+ '0100' || -- width (uint16 1)
+ '0100' || -- height (uint16 1)
+ '00' || -- first band type (1BB)
+ '00' ||-- novalue==0
+ '02' -- pixel(0,0)==2 (out of 0..1 range)
+)::raster;
+
+-- Out of range value for 2BUI pixeltype
+SELECT (
+ '01' || -- little endian (uint8 ndr)
+ '0000' || -- version (uint16 0)
+ '0100' || -- nBands (uint16 1)
+ '000000000000F03F' || -- scaleX (float64 1)
+ '000000000000F03F' || -- scaleY (float64 1)
+ '0000000000000000' || -- ipX (float64 0)
+ '0000000000000000' || -- ipY (float64 0)
+ '0000000000000000' || -- skewX (float64 0)
+ '0000000000000000' || -- skewY (float64 0)
+ '0A000000' || -- SRID (int32 10)
+ '0100' || -- width (uint16 1)
+ '0100' || -- height (uint16 1)
+ '01' || -- first band type (2BUI)
+ '00' ||-- novalue==0
+ '04' -- pixel(0,0)==4 (out of 0..3 range)
+)::raster;
+
+-- Out of range value for 4BUI pixeltype
+SELECT (
+ '01' || -- little endian (uint8 ndr)
+ '0000' || -- version (uint16 0)
+ '0100' || -- nBands (uint16 1)
+ '000000000000F03F' || -- scaleX (float64 1)
+ '000000000000F03F' || -- scaleY (float64 1)
+ '0000000000000000' || -- ipX (float64 0)
+ '0000000000000000' || -- ipY (float64 0)
+ '0000000000000000' || -- skewX (float64 0)
+ '0000000000000000' || -- skewY (float64 0)
+ '0A000000' || -- SRID (int32 10)
+ '0100' || -- width (uint16 1)
+ '0100' || -- height (uint16 1)
+ '02' || -- first band type (4BUI)
+ '00' ||-- novalue==0
+ '10' -- pixel(0,0)==16 (out of 0..15 range)
+)::raster;
Modified: spike/wktraster/rt_pg/test/io_expected
===================================================================
--- spike/wktraster/rt_pg/test/io_expected 2009-02-06 13:20:48 UTC (rev 3669)
+++ spike/wktraster/rt_pg/test/io_expected 2009-02-06 16:58:58 UTC (rev 3670)
@@ -11,3 +11,6 @@
1x1 single band (32BF) no transform|t|t
1x1 single band (64BF) no transform|t|t
1x1 single band (64BF external) no transform|t|t
+ERROR: Invalid value 2 for pixel of type 1BB
+ERROR: Invalid value 4 for pixel of type 2BUI
+ERROR: Invalid value 16 for pixel of type 4BUI
More information about the postgis-commits
mailing list