Skip to content

Commit 923f1da

Browse files
joehnignodet
authored andcommitted
Fix endless loop caused by aborted subsequent PI or comment.
1 parent 4b66cd7 commit 923f1da

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3897,7 +3897,7 @@ private char more()
38973897
fillBuf();
38983898
// this return value should be ignored as it is used in epilog parsing ...
38993899
if ( reachedEnd )
3900-
return (char) -1;
3900+
throw new EOFException( "no more data available" + getPositionDescription() );
39013901
}
39023902
final char ch = buf[pos++];
39033903
// line/columnNumber

src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,58 @@ public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark()
724724
*
725725
* @throws java.lang.Exception if any.
726726
*/
727+
@Test
728+
public void testSubsequentAbortedProcessingInstruction()
729+
throws Exception
730+
{
731+
MXParser parser = new MXParser();
732+
StringBuilder sb = new StringBuilder();
733+
sb.append( "<project />" );
734+
sb.append( "<?aborted" );
735+
736+
parser.setInput( new StringReader( sb.toString() ) );
737+
738+
try
739+
{
740+
assertEquals( XmlPullParser.START_TAG, parser.next() );
741+
assertEquals( XmlPullParser.END_TAG, parser.next() );
742+
assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.next() );
743+
744+
fail( "Should fail since it has aborted PI" );
745+
}
746+
catch ( XmlPullParserException ex )
747+
{
748+
assertTrue( ex.getMessage().contains( "@1:21" ) );
749+
assertTrue( ex.getMessage().contains( "processing instruction started on line 1 and column 12 was not closed" ) );
750+
}
751+
}
752+
753+
@Test
754+
public void testSubsequentAbortedComment()
755+
throws Exception
756+
{
757+
MXParser parser = new MXParser();
758+
StringBuilder sb = new StringBuilder();
759+
sb.append( "<project />" );
760+
sb.append( "<!-- aborted" );
761+
762+
parser.setInput( new StringReader( sb.toString() ) );
763+
764+
try
765+
{
766+
assertEquals( XmlPullParser.START_TAG, parser.next() );
767+
assertEquals( XmlPullParser.END_TAG, parser.next() );
768+
assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.next() );
769+
770+
fail( "Should fail since it has aborted comment" );
771+
}
772+
catch ( XmlPullParserException ex )
773+
{
774+
assertTrue( ex.getMessage().contains( "@1:24" ) );
775+
assertTrue( ex.getMessage().contains( "comment started on line 1 and column 12 was not closed" ) );
776+
}
777+
}
778+
727779
@Test
728780
public void testMalformedXMLRootElement()
729781
throws Exception

0 commit comments

Comments
 (0)