Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ dependencies {
apiv("org.apache.commons:commons-dbcp2")
apiv("org.apache.commons:commons-math3")
apiv("org.apache.commons:commons-pool2")
apiv("org.apache.commons:commons-secure-xml")
apiv("org.apache.commons:commons-collections4")
apiv("org.apache.commons:commons-text")
apiv("org.apache.geode:geode-core")
Expand Down
1 change: 1 addition & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ dependencies {
implementation("net.hydromatic:aggdesigner-algorithm")
implementation("org.apache.commons:commons-dbcp2")
implementation("org.apache.commons:commons-math3")
implementation("org.apache.commons:commons-secure-xml")
implementation("org.apache.commons:commons-text")
implementation("org.jooq:joou-java-6")
implementation("commons-io:commons-io")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.apache.calcite.linq4j.function.Experimental;
import org.apache.calcite.linq4j.function.Strict;

import org.apache.commons.xml.secure.SecureSAXParserFactory;

import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
Expand All @@ -31,14 +33,17 @@
import org.locationtech.jts.io.WKTWriter;
import org.locationtech.jts.io.geojson.GeoJsonReader;
import org.locationtech.jts.io.geojson.GeoJsonWriter;
import org.locationtech.jts.io.gml2.GMLReader;
import org.locationtech.jts.io.gml2.GMLHandler;
import org.locationtech.jts.io.gml2.GMLWriter;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.io.StringReader;
import java.util.Locale;
import java.util.regex.Pattern;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;

import static java.lang.Integer.parseInt;

Expand Down Expand Up @@ -130,16 +135,31 @@ public static Geometry fromGeoJson(String geoJson) {
/**
* Constructs a geometry from a GML representation.
*
* <p>The GML is parsed by a SAX parser from Apache Commons Secure XML, which
* does not fetch external DTDs or entities.
*
* @param gml a GML
* @return a geometry
*/
public static Geometry fromGml(String gml) {
final SAXParser parser;
try {
// Not namespace-aware, like JTS's GMLReader:
// GML values may use an undeclared "gml:" prefix
parser = SecureSAXParserFactory.newInstance().newSAXParser();
} catch (ParserConfigurationException | SAXException e) {
// Tested parsers reject unsupported features eagerly in the factory, not in
// newSAXParser, so an exception here indicates a classpath problem
throw new IllegalStateException(e);
}
@SuppressWarnings("argument.type.incompatible") // delegate is documented as nullable
final GMLHandler handler = new GMLHandler(GEOMETRY_FACTORY, null);
try {
GMLReader reader = new GMLReader();
return reader.read(gml, GEOMETRY_FACTORY);
} catch (SAXException | IOException | ParserConfigurationException e) {
parser.parse(new InputSource(new StringReader(gml)), handler);
} catch (SAXException | IOException e) {
throw new RuntimeException("Unable to parse GML");
}
return handler.getGeometry();
}

/**
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ commons-dbcp2.version=2.11.0
commons-io.version=2.15.0
commons-math3.version=3.6.1
commons-pool2.version=2.12.0
commons-secure-xml.version=1.0.0
commons-collections4.version=4.4
commons-text.version=1.11.0
dropwizard-metrics.version=4.0.5
Expand Down
9 changes: 9 additions & 0 deletions src/main/config/forbidden-apis/signatures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,12 @@ java.net.URL#<init>(java.net.URL, java.lang.String, java.net.URLStreamHandler)
java.net.URL#<init>(java.lang.String, java.lang.String, int, java.lang.String)
java.net.URL#<init>(java.lang.String, java.lang.String, java.lang.String)
java.net.URL#<init>(java.lang.String, java.lang.String, int, java.lang.String, java.net.URLStreamHandler)

# Only Java 8 methods: Gradle may run on Java 8, where signatures of
# newer methods fail to parse, and code compiled for Java 8 cannot call them
@defaultMessage Use org.apache.commons.xml.secure.SecureSAXParserFactory instead
javax.xml.parsers.SAXParserFactory#newInstance(**)
org.xml.sax.helpers.XMLReaderFactory#createXMLReader(**)

@defaultMessage GMLReader creates an unsecured SAX parser; parse with GMLHandler and SecureSAXParserFactory instead
org.locationtech.jts.io.gml2.GMLReader
Loading