Changeset 9664 in josm for trunk/src


Ignore:
Timestamp:
2016-01-28T22:19:39+01:00 (4 years ago)
Author:
wiktorn
Message:

Fix NPE and hang when adding erroneus imageries.

When user points to a getCapabilities document that is XHTML file, parser was by default loading external entities. For XHTML, it was trying to load for ex.: http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd - which takes about 15 seconds to load. It referes to other external entities, that take no shorter to load, hence was the hang.

Now factory will not try to load external resources, nor validate the XML, so this should prevent such errors.

See: #12450

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java

    r9620 r9664  
    268268    private Collection<Layer> getCapabilities() throws IOException {
    269269        XMLInputFactory factory = XMLInputFactory.newFactory();
     270        // do not try to load external entities, nor validate the XML
     271        factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
     272        factory.setProperty(XMLInputFactory.IS_VALIDATING, false);
     273        factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
     274
    270275        InputStream in = new CachedFile(baseUrl).
    271276                setHttpHeaders(headers).
     
    280285            XMLStreamReader reader = factory.createXMLStreamReader(new ByteArrayInputStream(data));
    281286
    282             Collection<Layer> ret = null;
     287            Collection<Layer> ret = new ArrayList<>();
    283288            for (int event = reader.getEventType(); reader.hasNext(); event = reader.next()) {
    284289                if (event == XMLStreamReader.START_ELEMENT) {
Note: See TracChangeset for help on using the changeset viewer.