Return-Path: Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: (qmail 39454 invoked from network); 22 Jan 2011 07:26:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 22 Jan 2011 07:26:11 -0000 Received: (qmail 27183 invoked by uid 500); 22 Jan 2011 07:26:11 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 26899 invoked by uid 500); 22 Jan 2011 07:26:09 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 26889 invoked by uid 99); 22 Jan 2011 07:26:08 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Jan 2011 07:26:08 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.22] (HELO thor.apache.org) (140.211.11.22) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Jan 2011 07:26:06 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id p0M7PilR027681 for ; Sat, 22 Jan 2011 07:25:45 GMT Message-ID: <12511223.123461295681144909.JavaMail.jira@thor> Date: Sat, 22 Jan 2011 02:25:44 -0500 (EST) From: "Julius Davies (JIRA)" To: issues@commons.apache.org Subject: [jira] Updated: (CODEC-105) ArrayIndexOutOfBoundsException when doing multiple reads() on encoding b64InputStream MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/CODEC-105?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Julius Davies updated CODEC-105: -------------------------------- Attachment: codec-105.patch This fixes the bug by removing the "little optimization". The fix is actually 99% code removal, and it makes the overall base64 code a bit simpler, and should result in higher code-coverage percentages, since I think this "little optimization" was hard to cover. Mea culpa: the "little optimization" was my own foolish idea from the beginning (it's there in my original CODEC-69 patch), and I've felt funny about it for a long time. Now that I see it's even causing a real bug I'm very much +1 for purging it!!! Sorry! > 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 > Attachments: codec-105-junit-including-ASL2-license.patch, codec-105.patch > > > 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.