Skip to content

Commit

Permalink
Fix endless loop caused by aborted subsequent PI or comment (#124)
Browse files Browse the repository at this point in the history
This closes #124
  • Loading branch information
joehni authored and michael-o committed May 17, 2022
1 parent 11c749d commit 0d97c8b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3964,7 +3964,7 @@ private char more()
fillBuf();
// this return value should be ignored as it is used in epilog parsing ...
if ( reachedEnd )
return (char) -1;
throw new EOFException( "no more data available" + getPositionDescription() );
}
final char ch = buf[pos++];
// line/columnNumber
Expand Down
52 changes: 52 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 @@ -726,6 +726,58 @@ public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark()
*
* @throws java.lang.Exception if any.
*/
@Test
public void testSubsequentAbortedProcessingInstruction()
throws Exception
{
MXParser parser = new MXParser();
StringBuilder sb = new StringBuilder();
sb.append( "<project />" );
sb.append( "<?aborted" );

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

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

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

@Test
public void testSubsequentAbortedComment()
throws Exception
{
MXParser parser = new MXParser();
StringBuilder sb = new StringBuilder();
sb.append( "<project />" );
sb.append( "<!-- aborted" );

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

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

fail( "Should fail since it has aborted comment" );
}
catch ( XmlPullParserException ex )
{
assertTrue( ex.getMessage().contains( "@1:24" ) );
assertTrue( ex.getMessage().contains( "comment started on line 1 and column 12 was not closed" ) );
}
}

@Test
public void testMalformedXMLRootElement()
throws Exception
Expand Down

0 comments on commit 0d97c8b

Please sign in to comment.