commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Julius Davies (JIRA)" <j...@apache.org>
Subject [jira] Issue Comment Edited: (CODEC-105) ArrayIndexOutOfBoundsException when doing multiple reads() on encoding b64InputStream
Date Sat, 22 Jan 2011 01:32:44 GMT

    [ https://issues.apache.org/jira/browse/CODEC-105?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12985026#action_12985026
] 

Julius Davies edited comment on CODEC-105 at 1/21/11 8:31 PM:
--------------------------------------------------------------

It's related to these lines in Base64InputStream:


{code}

    169                     // A little optimization to avoid System.arraycopy()
    170                     // when possible.
    171                     if (c > 0 && b.length == len) {
    172                         base64.setInitialBuffer(b, offset, len);
    173                     }
{code}

I guess it's true what they say:  "premature optimization....."   Anyway, I'll look into this
and get it sorted out in a couple days.

      was (Author: juliusdavies):
    It's related to these lines in Base64InputStream:


{code}
    169                     // A little optimization to avoid System.arraycopy()
    170                     // when possible.
    171                     if (c > 0 && b.length == len) {
    172                         base64.setInitialBuffer(b, offset, len);
    173                     }
{code}

I guess it's true what they say:  "premature optimization....."   Anyway, I'll look into this
and get it sorted out in a couple days.
  
> ArrayIndexOutOfBoundsException when doing multiple reads() on encoding b64InputStream
> -------------------------------------------------------------------------------------
>
>                 Key: CODEC-105
>                 URL: https://issues.apache.org/jira/browse/CODEC-105
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>         Environment: 64-bit Linux
>            Reporter: ZAK Magnus
>            Assignee: Julius Davies
>
> When encoding a sizable stream byte by byte (so, just calling Base64InputStream.read()),
after 10920 successful read()s, this happens: 
> java.lang.ArrayIndexOutOfBoundsException: 2
>         at org.apache.commons.codec.binary.Base64.encode(Base64.java:502)
>         at org.apache.commons.codec.binary.Base64InputStream.read(Base64InputStream.java:157)
>         at org.apache.commons.codec.binary.Base64InputStream.read(Base64InputStream.java:109)
> Based on this, the necessary conditions seem to be that buffer = null and modulus = 2.
Then, if a read() is done, a single-byte buffer is used, whose length is doubled by resizeBuffer(),
but that still doesn't make it big enough to hold the 4 bytes written to it because modulus
was just incremented to 0. 
> Here's some sample code:
> import org.apache.commons.codec.binary.Base64InputStream;
> public class TestReads {
>     public static void main(String[] args) {
>         Base64InputStream b64stream = new Base64InputStream(System.in, true, 0, null);
>         int n = 0;
>         try {
>             while (b64stream.read() != -1) n++;
>         } catch (Exception x) {
>             System.out.println(n);
>             x.printStackTrace();
>         }
>     }
> }

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


Mime
View raw message