]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1625] java.lang.ArrayIndexOutOfBoundsException from parsing maven-metadata.xml
authorOlivier Lamy <olamy@apache.org>
Thu, 19 Apr 2012 09:17:44 +0000 (09:17 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 19 Apr 2012 09:17:44 +0000 (09:17 +0000)
Submitted by charlie kim.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1327885 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-xml-tools/src/main/java/org/apache/archiva/xml/LatinEntityResolutionReader.java
archiva-modules/archiva-base/archiva-xml-tools/src/test/java/org/apache/archiva/xml/LatinEntityResolutionReaderTest.java

index 5bb607b0f92b560ffc219d1f86aaa0639215d8a1..f395ad290b5bb6f69256a2efd24fe03b9c40fa04 100644 (file)
@@ -69,12 +69,13 @@ public class LatinEntityResolutionReader
             {
                 // Copy partial leftover.
                 System.arraycopy( leftover, 0, destbuf, current_requested_offset, length );
+                int copyLeftOverLength = leftover.length - length;
 
                 // Create new leftover of remaining.
-                char tmp[] = new char[length];
-                System.arraycopy( leftover, length, tmp, 0, length );
+                char tmp[] = new char[copyLeftOverLength];
+                System.arraycopy( leftover, length, tmp, 0, copyLeftOverLength );
                 leftover = new char[tmp.length];
-                System.arraycopy( tmp, 0, leftover, 0, length );
+                System.arraycopy( tmp, 0, leftover, 0, copyLeftOverLength );
 
                 // Return len
                 return length;
index f65d78a6c68df92867c2b3c9e71504c6a7f9dc03..8659b3a8dc76ccd75e7c29903334a1a833c32c28 100644 (file)
@@ -23,8 +23,17 @@ import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.Reader;
 import java.io.StringWriter;
+import java.net.URL;
+
+import junit.framework.Assert;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.io.SAXReader;
 
 /**
  * LatinEntityResolutionReaderTest 
@@ -193,6 +202,29 @@ public class LatinEntityResolutionReaderTest
         assertProperRead( expected, "no-prolog-with-entities.xml", 409600 );
     }
 
+    
+    
+    public void testReaderLeftOver()
+    throws IOException
+       {
+           File inputFile = getExampleXml( "maven-metadata-leftover.xml" );
+           //Bits from RepositoryMetadataReader.read
+               InputStream in = null;
+               SAXReader reader = new SAXReader();
+               URL url = inputFile.toURL();
+               in = url.openStream();
+               InputStreamReader inReader = new InputStreamReader( in, "UTF-8" );
+               LatinEntityResolutionReader latinReader = new LatinEntityResolutionReader( inReader );
+               try {
+                       reader.read( latinReader );
+               } catch (DocumentException e) {
+                       Assert.fail("Should not have failed here." + e);
+                       throw new IOException(e);
+               }
+       }
+
+
+    
     public void testNoLatinEntitiesHugeLine()
     {
         assertProperRead( "commons-codec-1.2.pom", "commons-codec-1.2.pom", 4096 );