Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 9277 invoked from network); 17 Aug 2010 14:58:33 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 17 Aug 2010 14:58:33 -0000 Received: (qmail 33434 invoked by uid 500); 17 Aug 2010 14:58:33 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 33367 invoked by uid 500); 17 Aug 2010 14:58:32 -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 33355 invoked by uid 99); 17 Aug 2010 14:58:31 -0000 Received: from Unknown (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Aug 2010 14:58:31 +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.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Aug 2010 14:58:13 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B00C323889DA; Tue, 17 Aug 2010 14:56:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r986345 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/Blob.java engine/org/apache/derby/impl/jdbc/EmbedBlob.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobSetBytesBoundaryTest.java Date: Tue, 17 Aug 2010 14:56:55 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100817145655.B00C323889DA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kahatlen Date: Tue Aug 17 14:56:55 2010 New Revision: 986345 URL: http://svn.apache.org/viewvc?rev=986345&view=rev Log: DERBY-3898: Blob.setBytes differs between embedded and client driver when the specified length is invalid Added fix and test case for a remaining corner case: When the sum of offset and length is greater than Integer.MAX_VALUE, the client driver silently ignores the error whereas the embedded driver fails with an IndexOutOfBoundsException. The unexpected results are caused by a check for offset + len > bytes.length where offset+len overflows and evaluates to a negative value. The fix changes this condition to the equivalent len > bytes.length - offset which won't overflow (because both bytes.length and offset are known to be non-negative at this point in the code, and subtracting one non-negative int from another is guaranteed to result in a value in the range [-Integer.MAX_VALUE, Integer.MAX_VALUE]). Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Blob.java db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobSetBytesBoundaryTest.java Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Blob.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Blob.java?rev=986345&r1=986344&r2=986345&view=diff ============================================================================== --- db/derby/code/trunk/java/client/org/apache/derby/client/am/Blob.java (original) +++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Blob.java Tue Aug 17 14:56:55 2010 @@ -469,7 +469,7 @@ public class Blob extends Lob implements if (len == 0) { return 0; } - if (len + offset > bytes.length) { + if (len > bytes.length - offset) { throw new SqlException(agent_.logWriter_, new ClientMessageId(SQLState.BLOB_LENGTH_TOO_LONG), new Integer(len)); Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java?rev=986345&r1=986344&r2=986345&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java Tue Aug 17 14:56:55 2010 @@ -898,7 +898,7 @@ final class EmbedBlob extends Connection if (len == 0) { return 0; } - if (len + offset > bytes.length) { + if (len > bytes.length - offset) { throw Util.generateCsSQLException(SQLState.BLOB_LENGTH_TOO_LONG, new Long(len)); } Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobSetBytesBoundaryTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobSetBytesBoundaryTest.java?rev=986345&r1=986344&r2=986345&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobSetBytesBoundaryTest.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobSetBytesBoundaryTest.java Tue Aug 17 14:56:55 2010 @@ -90,7 +90,16 @@ public class BlobSetBytesBoundaryTest ex } catch (SQLException sqle) { assertSQLState("XJ079", sqle); } - + + // Also check that we fail with the expected error if the sum of + // offset and length is greater than Integer.MAX_VALUE. + try { + blob.setBytes(1, new byte[100], 10, Integer.MAX_VALUE); + fail("setBytes() should fail when offset+length > bytes.length"); + } catch (SQLException sqle) { + assertSQLState("XJ079", sqle); + } + stmt.close(); }