Skip to content

Commit

Permalink
[GEOS-8090] Prevent broken DXF on empty input
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Watermeyer authored and aaime committed Apr 29, 2017
1 parent f4e1a0a commit 2a8e69d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
Expand Down Expand Up @@ -193,17 +193,20 @@ protected ReferencedEnvelope getEnvelope(List featureList) {
* Normalizes an envelope to get a usable viewport.
*
* @param e2
*
*/
private ReferencedEnvelope normalizeEnvelope(ReferencedEnvelope e) {
if (e != null) {
private ReferencedEnvelope normalizeEnvelope(ReferencedEnvelope pEnv) {
if (pEnv != null) {
// if it's empty, get a 1 meter envelope around it
if (e.getWidth() == 0 && e.getHeight() == 0) {
e.expandBy(1);
if (pEnv.getWidth() == 0 && pEnv.getHeight() == 0) {
// no features or no geom, enable creation of valid empty file at least
pEnv.init(0d, 1d, 0d, 1d);
}
} else {
// no data, enable creation of empty file at least
pEnv = new ReferencedEnvelope();
pEnv.init(0d, 1d, 0d, 1d);
}
return e;

return pEnv;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* (c) 2014 - 2016 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
Expand All @@ -12,10 +12,8 @@
import static org.junit.Assert.fail;

import org.geoserver.data.test.SystemTestData;
import org.geoserver.platform.GeoServerExtensions;
import org.geoserver.wfs.WFSTestSupport;
import org.junit.Test;

import org.springframework.mock.web.MockHttpServletResponse;

/**
Expand Down Expand Up @@ -166,6 +164,31 @@ public void testMultiPolygons() throws Exception {
checkSequence(sResponse,new String[] {"LWPOLYLINE","LWPOLYLINE"},pos);
}

/**
* Bounding Box excludes all features. Envelope is empty Envelop.expandBy(1) is still empty.
* Division by zero. The result is an invalid character in DXF, entire file is invalid.
*/
@Test
public void testEmptyBbox() throws Exception {
MockHttpServletResponse resp = getAsServletResponse("wfs?request=GetFeature&version=1.1.0&typeName=MPolygons&outputFormat=dxf&bbox=929636,6013554.5,930744,6014601.5&srsName=EPSG:900913");
String sResponse = testBasicResult(resp, "MPolygons");
System.out.println(sResponse);
for (int i = 0; i < sResponse.length(); i++) {
char c = sResponse.charAt(i);
assertTrue("Invalid non-ASCII char: '"+c+"'", c < 128);
}
}

/**
* Test maxFeatures=0: No collection passed to writer, no geom. Result was: NPE
* Maybe exotic, but should not end in NPE.
*/
@Test
public void testEmptyCount() throws Exception {
MockHttpServletResponse resp = getAsServletResponse("wfs?request=GetFeature&version=1.1.0&typeName=MPolygons&outputFormat=dxf&maxFeatures=0");
testBasicResult(resp, "MPolygons");
}

/**
* Test format option asblocks.
*
Expand Down

0 comments on commit 2a8e69d

Please sign in to comment.