db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bryan Pendleton <bpendle...@amberpoint.com>
Subject Re: Question about splitQRYDTA and offbyone error message.
Date Sat, 24 Jun 2006 16:04:36 GMT
Sunitha Kambhampati wrote:
> they are hitting an edge case, where the writer.getDSSLength() is 
> equal to blksize and this DSS is the only dss in the send buffer. 

Hi Sunitha,

Yes, I completely agree with your analysis. There is an off-by-one
bug in the fix for DERBY-170. Thank you very much for the great description!

Below is a simple repro program that you can run to demonstrate the
bug for yourself. Compile it, then start up the Network Server and
run the program with "java newBug 12749". That exact length for column
"c2" will trigger the edge case you've found.

The fix is as simple as changing the >= to >, just as you said in your
message, I believe.

Should we re-open one of the existing bugs? I think it may be easier just
to file a new bug, and then verify the fix using the diff and the test
program below.

I'll work this up into a proper patch, with a new regression test,
probably as part of derbynet/prepStmt.java

Thanks again for tracking this down, and please let me know if you
can confirm these results.

thanks,

bryan

Index: java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
===================================================================
--- java/drda/org/apache/derby/impl/drda/DRDAConnThread.java    (revision 416929)
+++ java/drda/org/apache/derby/impl/drda/DRDAConnThread.java    (working copy)
@@ -6408,7 +6408,7 @@
                                 }
                         }
                         // does all this fit in one QRYDTA
-                       if (writer.getDSSLength() >= blksize)
+                       if (writer.getDSSLength() > blksize)
                         {
                                 splitQRYDTA(stmt, blksize);
                                 return false;
@@ -6588,7 +6588,7 @@

                 writer.writeByte(CodePoint.NULLDATA);
                 // does all this fit in one QRYDTA
-               if (writer.getDSSLength() >= blksize)
+               if (writer.getDSSLength() > blksize)
                 {
                         splitQRYDTA(stmt, blksize);
                 }


================================================================================


import java.sql.*;
import java.text.NumberFormat;

public class newBug {

     public static void main(String [] args) {

         try {
             System.out.println("Try repro with string of len " + args[0]);
             int c2Len = NumberFormat.getInstance().parse(args[0]).intValue();

             Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
             Connection conn = DriverManager.getConnection(
             "jdbc:derby://localhost:1527/testdb;create=true", "bah", "humbug");

             Statement st = conn.createStatement();
             PreparedStatement pSt = null;

             try {
                 st.execute("drop table t");
             } catch (SQLException se) {}
             st.execute("create table t(c1 varchar(20000),c2 varchar(30000))");

             char [] c1 = new char[20000];
             for (int i = 0; i < c1.length; i++)
                 c1[i] = Character.forDigit(i%10, 10);
             char [] c2 = new char[30000];
             for (int i = 0; i < c2Len; i++)
                 c2[i] = Character.forDigit(i%10, 10);

             pSt = conn.prepareStatement("insert into t values (?,?)");
             pSt.setString(1, new String(c1));
             pSt.setString(2, new String(c2,0, c2Len));

             pSt.execute();
             pSt.close();
             ResultSet rs = st.executeQuery("select * from t");
             while (rs.next())
                 System.out.println("Fetched a row, c2.length=" +
                         rs.getString("c2").length());
             rs.close();

             st.close();
             conn.close();
         } catch (Exception e) {
             System.out.println("-=- OOPS: Unexpected problem while trying " +
                 "to reproduce: ");
             e.printStackTrace();
         }
     }
}


Mime
View raw message