db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r955540 - in /db/derby/code/trunk/java/client/org/apache/derby/client: am/SignedBinary.java net/NetStatementRequest.java net/Request.java
Date Thu, 17 Jun 2010 10:31:30 GMT
Author: kristwaa
Date: Thu Jun 17 10:31:30 2010
New Revision: 955540

URL: http://svn.apache.org/viewvc?rev=955540&view=rev
Log:
DERBY-1595 (partial): Network server fails with DRDAProtocolException if a BLOB with size
2147483647 is streamed from client 

Fixed protocol disagreement, where the client sent eight bytes for the
extended length bytes and the server expected six bytes (changed the client
behavior).

Patch file: derby-1595-1a-client_write6bytes.diff


Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/SignedBinary.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/Request.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/SignedBinary.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/SignedBinary.java?rev=955540&r1=955539&r2=955540&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/SignedBinary.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/SignedBinary.java Thu Jun 17
10:31:30 2010
@@ -25,6 +25,9 @@ public class SignedBinary {
     private SignedBinary() {
     }
 
+    /** Maximum value that cen be encoded by 6 bytes (signed). */
+    public static final long MAX_LONG_6_BYTES_SIGNED = 0x7FFFFFFFFFFFL;
+
     /**
      * Unix byte-order for signed binary representations.
      */
@@ -101,6 +104,30 @@ public class SignedBinary {
     }
 
     /**
+     * Writes a Java long to a 6-byte big endian signed binary representation.
+     *
+     * @param buffer the buffer to write into
+     * @param offset the offset at which to start writing
+     * @param v the value to be written
+     *
+     * @throws IllegalArgumentException if the long value is too large to be
+     *      represented by six bytes.
+     */
+    public static void long6BytesToBigEndianBytes(byte[] buffer, int offset,
+                                                  long v) {
+        if (v > MAX_LONG_6_BYTES_SIGNED) {
+            throw new IllegalArgumentException("value too large to be " +
+                    "represented by six bytes (signed): " + v);
+        }
+        buffer[offset++] = (byte) ((v >>> 40) & 0xFF);
+        buffer[offset++] = (byte) ((v >>> 32) & 0xFF);
+        buffer[offset++] = (byte) ((v >>> 24) & 0xFF);
+        buffer[offset++] = (byte) ((v >>> 16) & 0xFF);
+        buffer[offset++] = (byte) ((v >>> 8) & 0xFF);
+        buffer[offset++] = (byte) ((v >>> 0) & 0xFF);
+    }
+
+    /**
      * Write a Java long to an 8-byte big endian signed binary representation.
      */
     public static final void longToBigEndianBytes(byte[] buffer, int offset, long v) {

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java?rev=955540&r1=955539&r2=955540&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java Thu
Jun 17 10:31:30 2010
@@ -1757,14 +1757,10 @@ public class NetStatementRequest extends
             writeShort((short) dataLength);
         } else if (protocolTypesAndLengths[i][1] == 0x8004) {
             writeInt((int) dataLength);  // 4 bytes to encode the length
-        } else if (protocolTypesAndLengths[i][1] == 0x8006)// 6 bytes to encode the length
-        {
-            writeLong(dataLength);
-        }
-        //throw new SqlException (netAgent_.logWriter_, "0x8006 lob place holders not yet
supported");
-        else if (protocolTypesAndLengths[i][1] == 0x8008)// 8 bytes to encode the length
-        {
-            writeLong(dataLength);
+        } else if (protocolTypesAndLengths[i][1] == 0x8006) {
+            writeLong6Bytes(dataLength); // 6 bytes to encode the length
+        } else if (protocolTypesAndLengths[i][1] == 0x8008) {
+            writeLong(dataLength); // 8 bytes to encode the length
         }
 
         if (dataLength != 0) {

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/Request.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/Request.java?rev=955540&r1=955539&r2=955540&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/Request.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/Request.java Thu Jun 17 10:31:30
2010
@@ -1551,6 +1551,20 @@ public class Request {
         offset_ += 4;
     }
 
+    /**
+     * Writes a long into the buffer, using six bytes.
+     *
+     * @param v the value to write
+     * @throws IllegalArgumentException if the long value is too large to be
+     *      represented by six bytes.
+     */
+    final void writeLong6Bytes(long v) {
+        ensureLength(offset_ + 6);
+        org.apache.derby.client.am.SignedBinary.long6BytesToBigEndianBytes(
+                bytes_, offset_, v);
+        offset_ += 6;
+    }
+
     // insert a java long into the buffer.
     final void writeLong(long v) {
         ensureLength(offset_ + 8);



Mime
View raw message