Skip to content

Commit 4b66cd7

Browse files
joehnignodet
authored andcommitted
Fix endless loop with invalid PI containing XML.
1 parent a936a9c commit 4b66cd7

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3105,6 +3105,10 @@ else if ( !seenInnerTag )
31053105
throw new XmlPullParserException( "processing instruction started on line " + curLine
31063106
+ " and column " + curColumn + " was not closed", this, null );
31073107
}
3108+
else
3109+
{
3110+
seenInnerTag = false;
3111+
}
31083112
}
31093113
else if ( ch == '<' )
31103114
{

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,37 @@ public void testProcessingInstructionsContainingXml()
430430
*
431431
* @throws java.lang.Exception if any.
432432
*/
433+
@Test
434+
public void testMalformedProcessingInstructionsContainingXmlNoClosingQuestionMark()
435+
throws Exception
436+
{
437+
StringBuffer sb = new StringBuffer();
438+
sb.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
439+
sb.append( "<project />\n" );
440+
sb.append( "<?pi\n" );
441+
sb.append( " <tag>\n" );
442+
sb.append( " </tag>>\n" );
443+
444+
MXParser parser = new MXParser();
445+
parser.setInput( new StringReader( sb.toString() ) );
446+
447+
try
448+
{
449+
assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() );
450+
assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() );
451+
assertEquals( XmlPullParser.START_TAG, parser.nextToken() );
452+
assertEquals( XmlPullParser.END_TAG, parser.nextToken() );
453+
assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() );
454+
assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() );
455+
456+
fail( "Should fail since it has invalid PI" );
457+
}
458+
catch ( XmlPullParserException ex )
459+
{
460+
assertTrue( ex.getMessage().contains( "processing instruction started on line 3 and column 1 was not closed" ) );
461+
}
462+
}
463+
433464
@Test
434465
public void testSubsequentProcessingInstructionShort()
435466
throws Exception

0 commit comments

Comments
 (0)