From 01d00a711a7b7383588cb25793953b11d225b651 Mon Sep 17 00:00:00 2001 From: bailuk Date: Sun, 3 Nov 2019 16:03:34 +0100 Subject: [PATCH] Fix loop when parsing broken gpx files --- .../aat/gpx/xml_parser/parser/TagParser.java | 6 ++++-- .../bailu/aat/gpx/xml_parser/parser/Util.java | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/ch/bailu/aat/gpx/xml_parser/parser/TagParser.java b/app/src/main/java/ch/bailu/aat/gpx/xml_parser/parser/TagParser.java index 71d4a1c3a..a4f4a2945 100644 --- a/app/src/main/java/ch/bailu/aat/gpx/xml_parser/parser/TagParser.java +++ b/app/src/main/java/ch/bailu/aat/gpx/xml_parser/parser/TagParser.java @@ -63,8 +63,10 @@ private boolean begins(XmlPullParser parser) throws XmlPullParserException { } private boolean ends(XmlPullParser parser) throws XmlPullParserException { - return parser.getEventType() == XmlPullParser.END_TAG - && (tag == null || Objects.equals(parser.getName(), tag)); + return parser.getEventType() == XmlPullParser.END_DOCUMENT || + + (parser.getEventType() == XmlPullParser.END_TAG && + (tag == null || Objects.equals(parser.getName(), tag))); } diff --git a/app/src/main/java/ch/bailu/aat/gpx/xml_parser/parser/Util.java b/app/src/main/java/ch/bailu/aat/gpx/xml_parser/parser/Util.java index 281bbac90..cdc16106b 100644 --- a/app/src/main/java/ch/bailu/aat/gpx/xml_parser/parser/Util.java +++ b/app/src/main/java/ch/bailu/aat/gpx/xml_parser/parser/Util.java @@ -6,22 +6,32 @@ import java.io.IOException; import ch.bailu.aat.gpx.xml_parser.scanner.Scanner; +import ch.bailu.aat.util.ui.AppLog; import ch.bailu.util_java.util.Objects; public class Util { + /** + * Read until tag ends or document ends + * + * @param parser + * @throws IOException + * @throws XmlPullParserException + */ public static void skipTag(XmlPullParser parser) throws IOException, XmlPullParserException { - String tag = parser.getName(); + final String tag = parser.getName(); - // log(parser); - while(tag != null) { + while (tag != null) { int event = parser.next(); if (event == XmlPullParser.END_TAG && Objects.equals(tag, parser.getName())) { - // log(parser); return; + + } else if (event == XmlPullParser.END_DOCUMENT) { + return; + } } }