summaryrefslogtreecommitdiffstats
path: root/archiva-modules
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2012-04-19 09:17:44 +0000
committerOlivier Lamy <olamy@apache.org>2012-04-19 09:17:44 +0000
commit037977e4262986f051adaad83907f077779bc432 (patch)
tree16a30adcac99b0a7b2da83f01c1e87fd03b0c9e7 /archiva-modules
parent1e79ae0703e511268341de5d58b3efb4932f4a0c (diff)
downloadarchiva-037977e4262986f051adaad83907f077779bc432.tar.gz
archiva-037977e4262986f051adaad83907f077779bc432.zip
[MRM-1625] java.lang.ArrayIndexOutOfBoundsException from parsing maven-metadata.xml
Submitted by charlie kim. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1327885 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
-rw-r--r--archiva-modules/archiva-base/archiva-xml-tools/src/main/java/org/apache/archiva/xml/LatinEntityResolutionReader.java7
-rw-r--r--archiva-modules/archiva-base/archiva-xml-tools/src/test/java/org/apache/archiva/xml/LatinEntityResolutionReaderTest.java32
2 files changed, 36 insertions, 3 deletions
diff --git a/archiva-modules/archiva-base/archiva-xml-tools/src/main/java/org/apache/archiva/xml/LatinEntityResolutionReader.java b/archiva-modules/archiva-base/archiva-xml-tools/src/main/java/org/apache/archiva/xml/LatinEntityResolutionReader.java
index 5bb607b0f..f395ad290 100644
--- a/archiva-modules/archiva-base/archiva-xml-tools/src/main/java/org/apache/archiva/xml/LatinEntityResolutionReader.java
+++ b/archiva-modules/archiva-base/archiva-xml-tools/src/main/java/org/apache/archiva/xml/LatinEntityResolutionReader.java
@@ -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;
diff --git a/archiva-modules/archiva-base/archiva-xml-tools/src/test/java/org/apache/archiva/xml/LatinEntityResolutionReaderTest.java b/archiva-modules/archiva-base/archiva-xml-tools/src/test/java/org/apache/archiva/xml/LatinEntityResolutionReaderTest.java
index f65d78a6c..8659b3a8d 100644
--- a/archiva-modules/archiva-base/archiva-xml-tools/src/test/java/org/apache/archiva/xml/LatinEntityResolutionReaderTest.java
+++ b/archiva-modules/archiva-base/archiva-xml-tools/src/test/java/org/apache/archiva/xml/LatinEntityResolutionReaderTest.java
@@ -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 );