db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r755906 - /db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/DDMReader.java
Date Thu, 19 Mar 2009 10:43:06 GMT
Author: kahatlen
Date: Thu Mar 19 10:43:05 2009
New Revision: 755906

URL: http://svn.apache.org/viewvc?rev=755906&view=rev
Log:
DERBY-4088: DDMReader readBytes ArrayIndexOutOfBoundsException

Merged revision 755866 from trunk.

Modified:
    db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/DDMReader.java

Modified: db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/DDMReader.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/DDMReader.java?rev=755906&r1=755905&r2=755906&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/DDMReader.java (original)
+++ db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/DDMReader.java Thu Mar
19 10:43:05 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);
 	}
@@ -1695,23 +1697,21 @@
 		throws DRDAProtocolException
 	{
 
-        // Offset from the start of the valid region of the byte buffer,
-        // pointing to the start of the DSS we're looking at.
-        int tempOffset = 0;
-
+		
 		// jump to the last continuation header.
+		int tempPos = 0;
 		for (int i = 0; i < continueDssHeaderCount; i++) 
 		{
 			// the first may be less than the size of a full DSS
 			if (i == 0) 
 			{
 				// only jump by the number of bytes remaining in the current DSS
-				tempOffset = dssLength;
+				tempPos = pos + dssLength;
 			}
 			else 
 			{
 				// all other jumps are for a full continued DSS
-				tempOffset += DssConstants.MAX_DSS_LENGTH;
+				tempPos += DssConstants.MAX_DSS_LENGTH;
 			}
 		}
 
@@ -1727,13 +1727,8 @@
 
 		for (int i = 0; i < continueDssHeaderCount; i++) 
 		{
-            // Get the length of the DSS. Make sure that we have enough data
-            // in the buffer to actually see the length (may not have enough
-            // bytes if this is not the first DSS).
-            ensureALayerDataInBuffer(tempOffset + 1);
-            continueHeaderLength =
-                    ((buffer[pos + tempOffset] & 0xff) << 8) +
-                    (buffer[pos + tempOffset + 1] & 0xff);
+			continueHeaderLength = ((buffer[tempPos] & 0xff) << 8) +
+				((buffer[tempPos + 1] & 0xff) << 0);
 
 			if (i == 0) 
 			{
@@ -1753,13 +1748,6 @@
 				}
 				// the very first shift size is 2
 				shiftSize = 2;
-
-                // Make sure we have all of the last DSS in the buffer
-                // (DERBY-4088). Since we look at the last DSS first,
-                // we don't need to do this for the other DSSs, as they
-                // will also be fetched into the buffer when we fetch the
-                // last one.
-                ensureALayerDataInBuffer(tempOffset + continueHeaderLength);
 			}
 			else 
 			{
@@ -1798,12 +1786,12 @@
 			else
 				bytesToShift = dssLength;
 
-			tempOffset -= (bytesToShift - 2);
-			System.arraycopy(buffer, pos + tempOffset - shiftSize,
-                             buffer, pos + tempOffset, bytesToShift);
+			tempPos -= (bytesToShift - 2);
+			System.arraycopy(buffer, tempPos - shiftSize, buffer, tempPos,
+							 bytesToShift);
 		}
 		// reposition the start of the data after the final DSS shift.
-		pos += tempOffset;
+		pos = tempPos;
 		dssLength += newdssLength;
 	}
 



Mime
View raw message