Author: sback
Date: 2007-06-16 17:26:06 +0000 (Sat, 16 Jun 2007)
New Revision: 13624

Modified:
   trunk/freenet/src/freenet/support/HexUtil.java
Log:
Added a check on length which throws an argument exception if fails. 
Consequently removed a useless check

Modified: trunk/freenet/src/freenet/support/HexUtil.java
===================================================================
--- trunk/freenet/src/freenet/support/HexUtil.java      2007-06-16 13:36:37 UTC 
(rev 13623)
+++ trunk/freenet/src/freenet/support/HexUtil.java      2007-06-16 17:26:06 UTC 
(rev 13624)
@@ -32,7 +32,7 @@
         * @return the string of hex chars.
         */
        public static final String bytesToHex(byte[] bs, int off, int length) {
-               if (bs.length <= off)
+               if (bs.length <= off || bs.length < off+length)
                        throw new IllegalArgumentException();
                StringBuffer sb = new StringBuffer(length * 2);
                bytesToHexAppend(bs, off, length, sb);
@@ -44,8 +44,10 @@
                int off,
                int length,
                StringBuffer sb) {
+               if (bs.length <= off || bs.length < off+length)
+                       throw new IllegalArgumentException();
                sb.ensureCapacity(sb.length() + length * 2);
-               for (int i = off; (i < (off + length)) && (i < bs.length); i++) 
{
+               for (int i = off; i < (off + length); i++) {
                        sb.append(Character.forDigit((bs[i] >>> 4) & 0xf, 16));
                        sb.append(Character.forDigit(bs[i] & 0xf, 16));
                }


Reply via email to