Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 61413 invoked from network); 19 Mar 2009 10:44:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Mar 2009 10:44:35 -0000 Received: (qmail 12290 invoked by uid 500); 19 Mar 2009 10:44:35 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 12219 invoked by uid 500); 19 Mar 2009 10:44:35 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 12210 invoked by uid 99); 19 Mar 2009 10:44:35 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Mar 2009 03:44:35 -0700 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.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Mar 2009 10:44:34 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 70522238896B; Thu, 19 Mar 2009 10:44:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r755907 - in /db/derby/code/branches/10.4/java: drda/org/apache/derby/impl/drda/DDMReader.java testing/org/apache/derbyTesting/functionTests/tests/derbynet/PrepareStatementTest.java Date: Thu, 19 Mar 2009 10:44:14 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090319104414.70522238896B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kahatlen Date: Thu Mar 19 10:44:13 2009 New Revision: 755907 URL: http://svn.apache.org/viewvc?rev=755907&view=rev Log: DERBY-4088: DDMReader readBytes ArrayIndexOutOfBoundsException Merged revision 752813 and revision 755866 from trunk. Modified: db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/DDMReader.java db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/PrepareStatementTest.java Modified: db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/DDMReader.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/DDMReader.java?rev=755907&r1=755906&r2=755907&view=diff ============================================================================== --- db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/DDMReader.java (original) +++ db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/DDMReader.java Thu Mar 19 10:44:13 2009 @@ -1669,16 +1669,18 @@ private void ensureBLayerDataInBuffer (int desiredDataSize, boolean adjustLen) throws DRDAProtocolException { - ensureALayerDataInBuffer (desiredDataSize); - if (dssIsContinued) - { - if (desiredDataSize > dssLength) - { - int continueDssHeaderCount = - (((desiredDataSize - dssLength) / DssConstants.MAX_DSS_LENGTH) + 1); - compressBLayerData (continueDssHeaderCount); - } - } + if (dssIsContinued && (desiredDataSize > dssLength)) { + // The data that we want is split across multiple DSSs + int continueDssHeaderCount = + (desiredDataSize - dssLength) / DssConstants.MAX_DSS_LENGTH + 1; + // Account for the extra header bytes (2 length bytes per DSS) + ensureALayerDataInBuffer( + desiredDataSize + 2 * continueDssHeaderCount); + compressBLayerData(continueDssHeaderCount); + } else { + ensureALayerDataInBuffer(desiredDataSize); + } + if (adjustLen) adjustLengths(desiredDataSize); } Modified: db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/PrepareStatementTest.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/PrepareStatementTest.java?rev=755907&r1=755906&r2=755907&view=diff ============================================================================== --- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/PrepareStatementTest.java (original) +++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/PrepareStatementTest.java Thu Mar 19 10:44:13 2009 @@ -32,11 +32,14 @@ import java.math.BigDecimal; import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream; import org.apache.derbyTesting.junit.BaseJDBCTestCase; import org.apache.derbyTesting.junit.TestConfiguration; import org.apache.derbyTesting.junit.JDBC; @@ -1296,4 +1299,31 @@ for (int i = 0; i < length; ++i) buf.append("X"); return buf.toString(); } + + /** + * Test fix for DERBY-4088 where an ArrayIndexOutOfBoundsException was + * thrown by DDMReader.readBytes() when reading a BLOB value whose length + * was close to the maximum length of a DSS. + */ + public void testReadBlobCloseToMaxDssLength() throws Exception { + final int length = 32766; // max DSS length is 32767 + + // Create test data with the requested length + DataInputStream stream1 = + new DataInputStream(new LoopingAlphabetStream(length)); + byte[] bytes = new byte[length]; + stream1.readFully(bytes); + + // See if the test data can be sent to the server and back with + // no errors. + PreparedStatement ps = prepareStatement("values cast(? as blob)"); + ps.setBytes(1, bytes); + ResultSet rs = ps.executeQuery(); + assertTrue("empty result set", rs.next()); + InputStream stream2 = rs.getBinaryStream(1); + assertEquals(new LoopingAlphabetStream(length), stream2); + assertFalse("too many rows", rs.next()); + rs.close(); + } + }