db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
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 GMT
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();
+    }
+
 }



Mime
View raw message