Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ecdbeeb

Browse filesBrowse files
mealingrhboutemy
authored andcommitted
Add fix for overflow error in MXParser buffer sizing
closes #72
1 parent 905a516 commit ecdbeeb
Copy full SHA for ecdbeeb

File tree

Expand file treeCollapse file tree

2 files changed

+28
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+28
-3
lines changed

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

Copy file name to clipboardExpand all lines: src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,11 @@ protected void ensureEntityCapacity()
401401
protected int bufLoadFactor = 95; // 99%
402402
// protected int bufHardLimit; // only matters when expanding
403403

404-
protected char buf[] = new char[Runtime.getRuntime().freeMemory() > 1000000L ? READ_CHUNK_SIZE : 256];
404+
protected float bufferLoadFactor = bufLoadFactor / 100f;
405405

406-
protected int bufSoftLimit = ( bufLoadFactor * buf.length ) / 100; // desirable size of buffer
406+
protected char buf[] = new char[Runtime.getRuntime().freeMemory() > 1000000L ? READ_CHUNK_SIZE : 256];
407+
408+
protected int bufSoftLimit = (int) ( bufferLoadFactor * buf.length ); // desirable size of buffer
407409

408410
protected boolean preventBufferCompaction;
409411

@@ -3656,7 +3658,8 @@ else if ( expand )
36563658
buf = newBuf;
36573659
if ( bufLoadFactor > 0 )
36583660
{
3659-
bufSoftLimit = ( bufLoadFactor * buf.length ) / 100;
3661+
// Include a fix for https://web.archive.org/web/20070831191548/http://www.extreme.indiana.edu/bugzilla/show_bug.cgi?id=228
3662+
bufSoftLimit = (int) ( bufferLoadFactor * buf.length );
36603663
}
36613664

36623665
}

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

Copy file name to clipboardExpand all lines: src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,28 @@ public void testSubsequentProcessingInstructionMoreThan8k()
391391
assertEquals( XmlPullParser.END_TAG, parser.nextToken() );
392392
}
393393

394+
@Test
395+
public void testLargeText_NoOverflow()
396+
throws Exception
397+
{
398+
StringBuffer sb = new StringBuffer();
399+
sb.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" );
400+
sb.append( "<largetextblock>" );
401+
// Anything above 33,554,431 would fail without a fix for
402+
// https://web.archive.org/web/20070831191548/http://www.extreme.indiana.edu/bugzilla/show_bug.cgi?id=228
403+
// with java.io.IOException: error reading input, returned 0
404+
sb.append( new String( new char[33554432] ) );
405+
sb.append( "</largetextblock>" );
406+
407+
MXParser parser = new MXParser();
408+
parser.setInput( new StringReader( sb.toString() ) );
409+
410+
assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() );
411+
assertEquals( XmlPullParser.START_TAG, parser.nextToken() );
412+
assertEquals( XmlPullParser.TEXT, parser.nextToken() );
413+
assertEquals( XmlPullParser.END_TAG, parser.nextToken() );
414+
}
415+
394416
public void testMalformedProcessingInstructionAfterTag()
395417
throws Exception
396418
{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.