Fix to convert BigInteger to 64 bit data when MSB is 1. 47/4047/1
authorDeepthi V V <deepthi.v.v@ericsson.com>
Tue, 7 Jan 2014 11:29:56 +0000 (16:59 +0530)
committerDeepthi V V <deepthi.v.v@ericsson.com>
Tue, 7 Jan 2014 11:29:56 +0000 (16:59 +0530)
When MSB is 1, BigInteger toByteArray resulted in 9 element byte array, which lead to ArrayIndexOutOfBoundsException.

Signed-off-by: Deepthi V V <deepthi.v.v@ericsson.com>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/util/ByteUtil.java

index dc6d5b5078b3a0a872eeeab323ec835816ffee03..32a4a59d6fb3b06d665e946c6753eaa13f99949b 100644 (file)
@@ -47,7 +47,11 @@ public abstract class ByteUtil {
         } else {
             Arrays.fill(outputArray, (byte) 0);
         }
-        System.arraycopy(inputArray, 0, outputArray, outputArray.length - inputArray.length, inputArray.length);
+        System.arraycopy(inputArray,
+                         Math.max(0, inputArray.length - outputArray.length),
+                         outputArray,
+                         Math.max(0, outputArray.length - inputArray.length),
+                         Math.min(outputArray.length, inputArray.length));
         return outputArray;
     }
 }