Changeset 17984 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2021-07-10T22:04:32+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #21011 - IAE when reading GPX file with extension (patch by Bjoeni, modified)

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxExtensionCollection.java

    r17846 r17984  
    1010import java.util.stream.Stream;
    1111
    12 import org.apache.commons.jcs3.access.exception.InvalidArgumentException;
    1312import org.openstreetmap.josm.io.GpxReader;
     13import org.openstreetmap.josm.tools.Logging;
    1414import org.xml.sax.Attributes;
    1515
     
    6161    /**
    6262     * Sets the value for the last child and pops it from the stack, so the next one will be added to its parent.
    63      * The qualified name is verified.
     63     * A warning is issued if the qualified name does not equal the currently opened child.
    6464     * @param qName the qualified name
    6565     * @param value the value
    6666     */
    6767    public void closeChild(String qName, String value) {
    68         if (childStack == null || childStack.isEmpty())
    69             throw new InvalidArgumentException("Can't close child " + qName + ", no element in stack.");
     68        if (childStack == null || childStack.isEmpty()) {
     69            Logging.warn("Can''t close child ''{0}'', no element in stack.", qName);
     70            return;
     71                }
    7072
    7173        GpxExtension child = childStack.pop();
    72 
    7374        String childQN = child.getQualifiedName();
    7475
    7576        if (!childQN.equals(qName))
    76             throw new InvalidArgumentException("Can't close child " + qName + ", must close " + childQN + " first.");
     77            Logging.warn("Couldn''t close child ''{0}'', closed ''{1}'' instead.", qName, childQN);
    7778
    7879        child.setValue(value);
  • trunk/src/org/openstreetmap/josm/io/GpxReader.java

    r17846 r17984  
    8484        private GpxExtensionCollection currentTrackExtensionCollection;
    8585        private Stack<State> states;
    86         private final Stack<String> elements = new Stack<>();
     86        private final Stack<String[]> elements = new Stack<>();
    8787
    8888        private StringBuilder accumulator = new StringBuilder();
     
    133133        @Override
    134134        public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
    135             elements.push(localName);
     135            elements.push(new String[] { namespaceURI, localName, qName });
    136136            switch(currentState) {
    137137            case INIT:
     
    610610
    611611        void tryToFinish() throws SAXException {
    612             List<String> remainingElements = new ArrayList<>(elements);
     612            List<String[]> remainingElements = new ArrayList<>(elements);
    613613            for (int i = remainingElements.size() - 1; i >= 0; i--) {
    614                 endElement(null, remainingElements.get(i), remainingElements.get(i));
     614                String[] e = remainingElements.get(i);
     615                endElement(e[0], e[1], e[2]);
    615616            }
    616617            endDocument();
Note: See TracChangeset for help on using the changeset viewer.