Skip to content

Commit

Permalink
Fix endless loop with invalid PI containing XML (#122)
Browse files Browse the repository at this point in the history
This closes #122
  • Loading branch information
joehni authored and michael-o committed May 17, 2022
1 parent 2c6fe7e commit 11c749d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3158,6 +3158,10 @@ else if ( !seenInnerTag )
throw new XmlPullParserException( "processing instruction started on line " + curLine
+ " and column " + curColumn + " was not closed", this, null );
}
else
{
seenInnerTag = false;
}
}
else if ( ch == '<' )
{
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,37 @@ public void testProcessingInstructionsContainingXml()
*
* @throws java.lang.Exception if any.
*/
@Test
public void testMalformedProcessingInstructionsContainingXmlNoClosingQuestionMark()
throws Exception
{
StringBuffer sb = new StringBuffer();
sb.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
sb.append( "<project />\n" );
sb.append( "<?pi\n" );
sb.append( " <tag>\n" );
sb.append( " </tag>>\n" );

MXParser parser = new MXParser();
parser.setInput( new StringReader( sb.toString() ) );

try
{
assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() );
assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() );
assertEquals( XmlPullParser.START_TAG, parser.nextToken() );
assertEquals( XmlPullParser.END_TAG, parser.nextToken() );
assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() );
assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() );

fail( "Should fail since it has invalid PI" );
}
catch ( XmlPullParserException ex )
{
assertTrue( ex.getMessage().contains( "processing instruction started on line 3 and column 1 was not closed" ) );
}
}

@Test
public void testSubsequentProcessingInstructionShort()
throws Exception
Expand Down

0 comments on commit 11c749d

Please sign in to comment.