Packet parsing should look for depth

Description

A packet with:

will cause Smack to disconnect. Packet parsing must keep track of depth to correctly figure out end tags.

This means that condition to determine the end tag also needs to check if the tag's name matches, which is already done, and that the depth must be the same as the corresponding start tag.

Environment

None

Activity

Show:

Florian Schmaus 
October 18, 2014 at 8:18 AM

Reworked Smack provider so that the initial depth is always provided. It's now up to the providers to replace the abort condition from

parser.getEvent() == END_TAG && parser.getName().equals("foo")

to

parser.getEvent() == END_TAG && parser.getDepth() == initialDepth

Message parsing has been adopted to look for the depth. Note that the example in the issue with <message><body><body/></body></message> will still cause a parsing exception, as it is invalid XMPP XML: body elements must not contain mixed mode XML.

Paul Johe 
May 14, 2006 at 7:36 PM

I have a suggestion to help resolve this issue. Use a customized MXParser:

import java.io.IOException;

import org.xmlpull.mxp1.MXParser;
import org.xmlpull.v1.XmlPullParserException;

public class SmackXMLPuller extends MXParser {

private int depth = 0;

private static final long serialVersionUID = 1L;

@Override
public int next() throws XmlPullParserException, IOException {
int ret = super.next();
if (ret == START_TAG)
depth++;
if (ret == END_TAG)
depth--;
return ret;
}

@Override
public int nextTag() throws XmlPullParserException, IOException {
int ret = next();
if (ret == START_TAG || ret == END_TAG)
return ret;
throw new XmlPullParserException("The next tag was not a start or end tag.");
}

/**

  • Get the current depth of the parser
    * @return int
    */
    public int getDepth() {
    return depth;
    }
    }

Fixed

Details

Assignee

Reporter

Components

Fix versions

Priority

Created July 23, 2005 at 2:46 AM
Updated March 29, 2015 at 10:42 AM
Resolved October 18, 2014 at 8:18 AM