You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Robert Rodewald (JIRA)" <ji...@apache.org> on 2008/04/30 11:18:55 UTC

[jira] Created: (CODEC-68) isBase64 throws ArrayIndexOutOfBoundsException on some non-BASE64 bytes

isBase64 throws ArrayIndexOutOfBoundsException on some non-BASE64 bytes
-----------------------------------------------------------------------

                 Key: CODEC-68
                 URL: https://issues.apache.org/jira/browse/CODEC-68
             Project: Commons Codec
          Issue Type: Bug
    Affects Versions: 1.3
            Reporter: Robert Rodewald


the following code throws an ArrayIndexOutOfBoundsException although it is perfectly valid (the byte 0x9c should be ignored according to the standard):

byte[x] = new byte[] { 'n', 'A', '=', '=', 0x9c };
Base64.decodeBase64(x);

The problem is the following method:

    private static boolean isBase64(byte octect) {
        if (octect == PAD) {
            return true;
        } else if (base64Alphabet[octect] == -1) {
            return false;
        } else {
            return true;
        }
    }

in Java octect is a *signed* value, so it is not correct to use it as an offset for an array [0..254] which base64Alphabet is. 0x9c is -100!

FIX:
use base64Alphabet[ 0xff & octect ] in the "else if" block to convert the octet prior using it as an offset for the lookup table

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CODEC-68) isBase64 throws ArrayIndexOutOfBoundsException on some non-BASE64 bytes

Posted by "Robert Rodewald (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CODEC-68?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Robert Rodewald updated CODEC-68:
---------------------------------

    Description: 
the following code throws an ArrayIndexOutOfBoundsException although it is perfectly valid (the byte 0x9c should be ignored according to the standard):

{code}
byte[x] = new byte[] { 'n', 'A', '=', '=', 0x9c };
Base64.decodeBase64(x);
{code}

The problem is the following method:

{code}
    private static boolean isBase64(byte octect) {
        if (octect == PAD) {
            return true;
        } else if (base64Alphabet[octect] == -1) {
            return false;
        } else {
            return true;
        }
    }
{code}

in Java octect is a *signed* value, so it is not correct to use it as an offset for an array [0..254] which base64Alphabet is. 0x9c is -100!

FIX:
use base64Alphabet[ 0xff & octect ] in the "else if" block to convert the octet prior using it as an offset for the lookup table

  was:
the following code throws an ArrayIndexOutOfBoundsException although it is perfectly valid (the byte 0x9c should be ignored according to the standard):

<code>
byte[x] = new byte[] { 'n', 'A', '=', '=', 0x9c };
Base64.decodeBase64(x);
</code>

The problem is the following method:

    private static boolean isBase64(byte octect) {
        if (octect == PAD) {
            return true;
        } else if (base64Alphabet[octect] == -1) {
            return false;
        } else {
            return true;
        }
    }

in Java octect is a *signed* value, so it is not correct to use it as an offset for an array [0..254] which base64Alphabet is. 0x9c is -100!

FIX:
use base64Alphabet[ 0xff & octect ] in the "else if" block to convert the octet prior using it as an offset for the lookup table


> isBase64 throws ArrayIndexOutOfBoundsException on some non-BASE64 bytes
> -----------------------------------------------------------------------
>
>                 Key: CODEC-68
>                 URL: https://issues.apache.org/jira/browse/CODEC-68
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.3
>            Reporter: Robert Rodewald
>   Original Estimate: 0.25h
>  Remaining Estimate: 0.25h
>
> the following code throws an ArrayIndexOutOfBoundsException although it is perfectly valid (the byte 0x9c should be ignored according to the standard):
> {code}
> byte[x] = new byte[] { 'n', 'A', '=', '=', 0x9c };
> Base64.decodeBase64(x);
> {code}
> The problem is the following method:
> {code}
>     private static boolean isBase64(byte octect) {
>         if (octect == PAD) {
>             return true;
>         } else if (base64Alphabet[octect] == -1) {
>             return false;
>         } else {
>             return true;
>         }
>     }
> {code}
> in Java octect is a *signed* value, so it is not correct to use it as an offset for an array [0..254] which base64Alphabet is. 0x9c is -100!
> FIX:
> use base64Alphabet[ 0xff & octect ] in the "else if" block to convert the octet prior using it as an offset for the lookup table

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CODEC-68) isBase64 throws ArrayIndexOutOfBoundsException on some non-BASE64 bytes

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CODEC-68?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated CODEC-68:
-------------------------------

    Fix Version/s: 1.4

> isBase64 throws ArrayIndexOutOfBoundsException on some non-BASE64 bytes
> -----------------------------------------------------------------------
>
>                 Key: CODEC-68
>                 URL: https://issues.apache.org/jira/browse/CODEC-68
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.3
>            Reporter: Robert Rodewald
>             Fix For: 1.4
>
>   Original Estimate: 0.25h
>  Remaining Estimate: 0.25h
>
> the following code throws an ArrayIndexOutOfBoundsException although it is perfectly valid (the byte 0x9c should be ignored according to the standard):
> {code}
> byte[x] = new byte[] { 'n', 'A', '=', '=', 0x9c };
> Base64.decodeBase64(x);
> {code}
> The problem is the following method:
> {code}
>     private static boolean isBase64(byte octect) {
>         if (octect == PAD) {
>             return true;
>         } else if (base64Alphabet[octect] == -1) {
>             return false;
>         } else {
>             return true;
>         }
>     }
> {code}
> in Java octect is a *signed* value, so it is not correct to use it as an offset for an array [0..254] which base64Alphabet is. 0x9c is -100!
> FIX:
> use base64Alphabet[ 0xff & octect ] in the "else if" block to convert the octet prior using it as an offset for the lookup table

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (CODEC-68) isBase64 throws ArrayIndexOutOfBoundsException on some non-BASE64 bytes

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CODEC-68?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell closed CODEC-68.
------------------------------

    Resolution: Duplicate

The relevant line of code has already been changed to:

        } else if (octect < 0 || base64Alphabet[octect] == -1) {

Thus it no longer gets an exception and is ignored.

> isBase64 throws ArrayIndexOutOfBoundsException on some non-BASE64 bytes
> -----------------------------------------------------------------------
>
>                 Key: CODEC-68
>                 URL: https://issues.apache.org/jira/browse/CODEC-68
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.3
>            Reporter: Robert Rodewald
>             Fix For: 1.4
>
>   Original Estimate: 0.25h
>  Remaining Estimate: 0.25h
>
> the following code throws an ArrayIndexOutOfBoundsException although it is perfectly valid (the byte 0x9c should be ignored according to the standard):
> {code}
> byte[x] = new byte[] { 'n', 'A', '=', '=', 0x9c };
> Base64.decodeBase64(x);
> {code}
> The problem is the following method:
> {code}
>     private static boolean isBase64(byte octect) {
>         if (octect == PAD) {
>             return true;
>         } else if (base64Alphabet[octect] == -1) {
>             return false;
>         } else {
>             return true;
>         }
>     }
> {code}
> in Java octect is a *signed* value, so it is not correct to use it as an offset for an array [0..254] which base64Alphabet is. 0x9c is -100!
> FIX:
> use base64Alphabet[ 0xff & octect ] in the "else if" block to convert the octet prior using it as an offset for the lookup table

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CODEC-68) isBase64 throws ArrayIndexOutOfBoundsException on some non-BASE64 bytes

Posted by "Robert Rodewald (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CODEC-68?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Robert Rodewald updated CODEC-68:
---------------------------------

    Description: 
the following code throws an ArrayIndexOutOfBoundsException although it is perfectly valid (the byte 0x9c should be ignored according to the standard):

<code>
byte[x] = new byte[] { 'n', 'A', '=', '=', 0x9c };
Base64.decodeBase64(x);
</code>

The problem is the following method:

    private static boolean isBase64(byte octect) {
        if (octect == PAD) {
            return true;
        } else if (base64Alphabet[octect] == -1) {
            return false;
        } else {
            return true;
        }
    }

in Java octect is a *signed* value, so it is not correct to use it as an offset for an array [0..254] which base64Alphabet is. 0x9c is -100!

FIX:
use base64Alphabet[ 0xff & octect ] in the "else if" block to convert the octet prior using it as an offset for the lookup table

  was:
the following code throws an ArrayIndexOutOfBoundsException although it is perfectly valid (the byte 0x9c should be ignored according to the standard):

byte[x] = new byte[] { 'n', 'A', '=', '=', 0x9c };
Base64.decodeBase64(x);

The problem is the following method:

    private static boolean isBase64(byte octect) {
        if (octect == PAD) {
            return true;
        } else if (base64Alphabet[octect] == -1) {
            return false;
        } else {
            return true;
        }
    }

in Java octect is a *signed* value, so it is not correct to use it as an offset for an array [0..254] which base64Alphabet is. 0x9c is -100!

FIX:
use base64Alphabet[ 0xff & octect ] in the "else if" block to convert the octet prior using it as an offset for the lookup table


> isBase64 throws ArrayIndexOutOfBoundsException on some non-BASE64 bytes
> -----------------------------------------------------------------------
>
>                 Key: CODEC-68
>                 URL: https://issues.apache.org/jira/browse/CODEC-68
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.3
>            Reporter: Robert Rodewald
>   Original Estimate: 0.25h
>  Remaining Estimate: 0.25h
>
> the following code throws an ArrayIndexOutOfBoundsException although it is perfectly valid (the byte 0x9c should be ignored according to the standard):
> <code>
> byte[x] = new byte[] { 'n', 'A', '=', '=', 0x9c };
> Base64.decodeBase64(x);
> </code>
> The problem is the following method:
>     private static boolean isBase64(byte octect) {
>         if (octect == PAD) {
>             return true;
>         } else if (base64Alphabet[octect] == -1) {
>             return false;
>         } else {
>             return true;
>         }
>     }
> in Java octect is a *signed* value, so it is not correct to use it as an offset for an array [0..254] which base64Alphabet is. 0x9c is -100!
> FIX:
> use base64Alphabet[ 0xff & octect ] in the "else if" block to convert the octet prior using it as an offset for the lookup table

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CODEC-68) isBase64 throws ArrayIndexOutOfBoundsException on some non-BASE64 bytes

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CODEC-68?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12594014#action_12594014 ] 

Henri Yandell commented on CODEC-68:
------------------------------------

I've added that as a unit test and it passes. I had to cast the 0x9c to a byte, but no other changes. I'll look later to see if the bugs already been caught and fixed.

> isBase64 throws ArrayIndexOutOfBoundsException on some non-BASE64 bytes
> -----------------------------------------------------------------------
>
>                 Key: CODEC-68
>                 URL: https://issues.apache.org/jira/browse/CODEC-68
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.3
>            Reporter: Robert Rodewald
>             Fix For: 1.4
>
>   Original Estimate: 0.25h
>  Remaining Estimate: 0.25h
>
> the following code throws an ArrayIndexOutOfBoundsException although it is perfectly valid (the byte 0x9c should be ignored according to the standard):
> {code}
> byte[x] = new byte[] { 'n', 'A', '=', '=', 0x9c };
> Base64.decodeBase64(x);
> {code}
> The problem is the following method:
> {code}
>     private static boolean isBase64(byte octect) {
>         if (octect == PAD) {
>             return true;
>         } else if (base64Alphabet[octect] == -1) {
>             return false;
>         } else {
>             return true;
>         }
>     }
> {code}
> in Java octect is a *signed* value, so it is not correct to use it as an offset for an array [0..254] which base64Alphabet is. 0x9c is -100!
> FIX:
> use base64Alphabet[ 0xff & octect ] in the "else if" block to convert the octet prior using it as an offset for the lookup table

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.