File tree 2 files changed +28
-3
lines changed
main/java/org/codehaus/plexus/util/xml/pull
test/java/org/codehaus/plexus/util/xml/pull
2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -401,9 +401,11 @@ protected void ensureEntityCapacity()
401
401
protected int bufLoadFactor = 95 ; // 99%
402
402
// protected int bufHardLimit; // only matters when expanding
403
403
404
- protected char buf [] = new char [ Runtime . getRuntime (). freeMemory () > 1000000L ? READ_CHUNK_SIZE : 256 ] ;
404
+ protected float bufferLoadFactor = bufLoadFactor / 100f ;
405
405
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
407
409
408
410
protected boolean preventBufferCompaction ;
409
411
@@ -3656,7 +3658,8 @@ else if ( expand )
3656
3658
buf = newBuf ;
3657
3659
if ( bufLoadFactor > 0 )
3658
3660
{
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 );
3660
3663
}
3661
3664
3662
3665
}
Original file line number Diff line number Diff line change @@ -391,6 +391,28 @@ public void testSubsequentProcessingInstructionMoreThan8k()
391
391
assertEquals ( XmlPullParser .END_TAG , parser .nextToken () );
392
392
}
393
393
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
+
394
416
public void testMalformedProcessingInstructionAfterTag ()
395
417
throws Exception
396
418
{
You can’t perform that action at this time.
0 commit comments