Skip to content

Commit

Permalink
[core] Increase resilience against faulty parser implementions
Browse files Browse the repository at this point in the history
If one of the parser throws a NullPointerException or
NumberFormatException, then this should not lead to a disconnect due
to an unhandled exception. Instead wrap those in an exception that is
handled by the parsing exception callback and ask the user to fill a
bug report for those faulty parsers.

We may adjust the list of exceptions that are wrapped in the future.
  • Loading branch information
Flowdalic committed Oct 15, 2024
1 parent 5dd08fc commit 02d8f53
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,14 @@ protected void parseAndProcessStanza(XmlPullParser parser)
int parserDepth = parser.getDepth();
Stanza stanza = null;
try {
stanza = PacketParserUtils.parseStanza(parser, incomingStreamXmlEnvironment);
try {
stanza = PacketParserUtils.parseStanza(parser, incomingStreamXmlEnvironment);
} catch (NullPointerException | NumberFormatException e) {
// Those exceptions should probably be wrapped into a SmackParsingException and therefore likely constitute a missing verification in the throwing parser.
String message = "Smack parser throw unexpected exception '" + e.getMessage() + "', please report this at " + Smack.BUG_REPORT_URL;
LOGGER.log(Level.SEVERE, message, e);
throw new IOException(message, e);
}
}
catch (XmlPullParserException | SmackParsingException | IOException | IllegalArgumentException e) {
CharSequence content = PacketParserUtils.parseContentDepth(parser,
Expand Down
14 changes: 13 additions & 1 deletion smack-core/src/main/java/org/jivesoftware/smack/Smack.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2020-2021 Florian Schmaus
* Copyright 2020-2024 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,8 @@
package org.jivesoftware.smack;

import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Logger;

import org.jivesoftware.smack.util.FileUtils;
Expand All @@ -29,6 +31,16 @@ public class Smack {

public static final String SMACK_PACKAGE = SMACK_ORG + ".smack";

public static final URL BUG_REPORT_URL;

static {
try {
BUG_REPORT_URL = new URL("https://discourse.igniterealtime.org/c/smack/smack-support/9");
} catch (MalformedURLException e) {
throw new ExceptionInInitializerError(e);
}
}

/**
* Returns the Smack version information, e.g."1.3.0".
*
Expand Down

0 comments on commit 02d8f53

Please sign in to comment.