GetMap request with transparent=true and format=image/png8 can result in ArrayIndexOutOfBoundsException
-------------------------------------------------------------------------------------------------------
Key: GEOS-4783
URL: https://jira.codehaus.org/browse/GEOS-4783
Project: GeoServer
Issue Type: Bug
Components: WMS
Affects Versions: 2.1.1
Reporter: Gabriel Roldán
Assignee: Simone Giannecchini
Priority: Critical
Hello, I think I should be reporting this issue in GEOT instead, but my worry is the coming GeoServer relase as this affects the png8 output of GWC.
To reproduce, make the following request against the cite:precip30min layer from the release data dir:
{code}
$ curl -v "http://localhost:8080/geoserver/wms?LAYERS=cite%3Aprecip30min&FORMAT=image%2Fpng8&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&&SRS=EPSG%3A4326&BBOX=-90,0,0,90&WIDTH=256&HEIGHT=256&transparent=true"
...
< HTTP/1.1 200 OK
< Content-Type: application/vnd.ogc.se_xml; charset=UTF-8
<
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE ServiceExceptionReport SYSTEM "http://localhost:8080/geoserver/schemas/wms/1.1.1/WMS_exception_1_1_1.dtd"> <ServiceExceptionReport version="1.1.1" > <ServiceException>
java.lang.ArrayIndexOutOfBoundsException: 2
2
Details:
org.geoserver.platform.ServiceException: java.lang.ArrayIndexOutOfBoundsException: 2
at org.geoserver.ows.Dispatcher.exception(Dispatcher.java:1324)
.....
Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
at org.geotools.image.palette.CustomPaletteBuilder.insertNode(CustomPaletteBuilder.java:380)
at org.geotools.image.palette.CustomPaletteBuilder.buildPalette(CustomPaletteBuilder.java:345)
at org.geoserver.wms.map.ImageUtils.forceIndexed8Bitmask(ImageUtils.java:265)
at org.geoserver.wms.map.RenderedImageMapResponse.forceIndexed8Bitmask(RenderedImageMapResponse.java:140)
at org.geoserver.wms.map.PNGMapResponse.formatImageOutputStream(PNGMapResponse.java:81)
at org.geoserver.wms.map.RenderedImageMapResponse.write(RenderedImageMapResponse.java:114)
... 60 more
{code}
It turns out that if the request comes with transparent=true, the resulting image is a 2-band one, and CustomPaletteBuilder has trouble with it.
The following patch seems to fix it:
{code}
diff --git a/modules/library/coverage/src/main/java/org/geotools/image/palette/CustomPaletteBuilder.java b/modules/library/coverage/src/main/java/org/geotools/image/palette/CustomPaletteBuilder.java
index d5f41da..9fe4452 100644
--- a/modules/library/coverage/src/main/java/org/geotools/image/palette/CustomPaletteBuilder.java
+++ b/modules/library/coverage/src/main/java/org/geotools/image/palette/CustomPaletteBuilder.java
@@ -376,8 +376,8 @@ public final class CustomPaletteBuilder {
final int numBands = rgba.length;
aNode.colorCount++;
aNode.red += rgba[0];
- aNode.green += rgba[numBands == 1 ? 0 : 1];
- aNode.blue += rgba[numBands == 1 ? 0 : 2];
+ aNode.green += rgba[numBands < 3 ? 0 : 1];
+ aNode.blue += rgba[numBands < 3 ? 0 : 2];
if (!aNode.isLeaf) {
int branchIndex = getBranchIndex(rgba, aLevel);
@@ -463,8 +463,8 @@ public final class CustomPaletteBuilder {
final int numBands = rgba.length;
int shift = maxLevel - aLevel;
int red_index = 0x1 & ((0xff & rgba[0]) >> shift);
- int green_index = 0x1 & ((0xff & rgba[numBands == 1 ? 0 : 1]) >> shift);
- int blue_index = 0x1 & ((0xff & rgba[numBands == 1 ? 0 : 2]) >> shift);
+ int green_index = 0x1 & ((0xff & rgba[numBands < 3? 0 : 1]) >> shift);
+ int blue_index = 0x1 & ((0xff & rgba[numBands < 3 ? 0 : 2]) >> shift);
int index = (red_index << 2) | (green_index << 1) | blue_index;
{code}
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira