List:Commits« Previous MessageNext Message »
From:Craig L Russell Date:February 4 2011 10:18pm
Subject:bzr commit into mysql-5.1-telco-7.1 branch (Craig.Russell:4083) Bug#59941
View as plain text  
#At file:///Users/clr/ndb/bzr-repo/mysql-5.1-telco-7.1/ based on revid:frazer@stripped

 4083 Craig L Russell	2011-02-04
      Bug #59941 VM crash invalid memory access with varbinary(256) column
      clusterj was incorrectly asking for the charset for a longvarbinary column.

    added:
      storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/VarbinaryTypesTest.java
      storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/model/VarbinaryTypes.java
      storage/ndb/clusterj/clusterj-tie/src/test/java/testsuite/clusterj/tie/VarbinaryTypesTest.java
    modified:
      storage/ndb/clusterj/clusterj-test/Makefile.am
      storage/ndb/clusterj/clusterj-test/src/main/resources/schema.sql
      storage/ndb/clusterj/clusterj-tie/src/main/java/com/mysql/clusterj/tie/ColumnImpl.java
=== modified file 'storage/ndb/clusterj/clusterj-test/Makefile.am'
--- a/storage/ndb/clusterj/clusterj-test/Makefile.am	2011-02-03 14:37:50 +0000
+++ b/storage/ndb/clusterj/clusterj-test/Makefile.am	2011-02-04 22:14:36 +0000
@@ -106,6 +106,7 @@ clusterj_test_java = \
   $(clusterj_test_src)/testsuite/clusterj/TimestampAsUtilDateTypesTest.java \
   $(clusterj_test_src)/testsuite/clusterj/TransactionStateTest.java \
   $(clusterj_test_src)/testsuite/clusterj/UpdateTest.java \
+  $(clusterj_test_src)/testsuite/clusterj/VarbinaryTypesTest.java \
   $(clusterj_test_src)/testsuite/clusterj/domaintypehandler/CrazyDomainTypeHandlerFactoryImpl.java \
   $(clusterj_test_src)/testsuite/clusterj/model/AllPrimitives.java \
   $(clusterj_test_src)/testsuite/clusterj/model/BadEmployeeNoPrimaryKeyAnnotationOnClass.java \

=== added file 'storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/VarbinaryTypesTest.java'
--- a/storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/VarbinaryTypesTest.java	1970-01-01 00:00:00 +0000
+++ b/storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/VarbinaryTypesTest.java	2011-02-04 22:14:36 +0000
@@ -0,0 +1,354 @@
+/*
+ *  Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+*/
+
+package testsuite.clusterj;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+
+import testsuite.clusterj.model.IdBase;
+import testsuite.clusterj.model.VarbinaryTypes;
+
+/** Test that Timestamps can be read and written. 
+ * case 1: Write using JDBC, read using NDB.
+ * case 2: Write using NDB, read using JDBC.
+ * Schema
+ *
+drop table if exists varbinarytypes;
+create table varbinarytypes (
+ id int not null primary key,
+
+ binary1 varbinary(1),
+ binary2 varbinary(2),
+ binary4 varbinary(4),
+ binary8 varbinary(8),
+ binary16 varbinary(16),
+ binary32 varbinary(32),
+ binary64 varbinary(64),
+ binary128 varbinary(128),
+ binary256 varbinary(256),
+ binary512 varbinary(512),
+ binary1024 varbinary(1024),
+ binary2048 varbinary(2048)
+
+) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
+
+ */
+public class VarbinaryTypesTest extends AbstractClusterJModelTest {
+
+    static int NUMBER_OF_INSTANCES = 10;
+
+    @Override
+    protected boolean getDebug() {
+        return false;
+    }
+
+    @Override
+    protected int getNumberOfInstances() {
+        return NUMBER_OF_INSTANCES;
+    }
+
+    @Override
+    protected String getTableName() {
+        return "varbinarytypes";
+    }
+
+    /** Subclasses override this method to provide the model class for the test */
+    @Override
+    Class<? extends IdBase> getModelClass() {
+        return VarbinaryTypes.class;
+    }
+
+    /** Subclasses override this method to provide values for rows (i) and columns (j) */
+    @Override
+    protected Object getColumnValue(int i, int j) {
+        // first calculate the length of the data
+        int length = (int)Math.pow(2, j);
+        byte[] data = new byte[length];
+        // fill in the data, increasing by one for each row, column, and byte in the byte[]
+        for (int d = 0; d < length; ++d) {
+            data[d] = (byte)(i + j + d);
+        }
+        return data;
+    }
+
+    /** Verify that the actual results match the expected results. If not, use the multiple error
+     * reporting method errorIfNotEqual defined in the superclass.
+     * @param where the location of the verification of results, normally the name of the test method
+     * @param expecteds the expected results
+     * @param actuals the actual results
+     */
+    @Override
+    protected void verify(String where, List<Object[]> expecteds, List<Object[]> actuals) {
+        for (int i = 0; i < expecteds.size(); ++i) {
+            Object[] expected = expecteds.get(i);
+            Object[] actual = actuals.get(i);
+            errorIfNotEqual(where + " got failure on id for row " + i, i, actual[0]);
+            for (int j = 1; j < expected.length; ++j) {
+                // verify each object in the array
+                byte[] expectedColumn = (byte[])(expected)[j];
+                byte[] actualColumn = (byte[])(actual)[j];
+                errorIfNotEqual(where + " got failure on length of data for row " + i,
+                        expectedColumn.length, actualColumn.length);
+                if (expectedColumn.length == actualColumn.length) {
+                    // now compare byte by byte
+                    for (j = 0; j < expectedColumn.length; ++j)
+                        errorIfNotEqual(where + " got failure on comparison of data for row "
+                                + i + " column " + j,
+                                expectedColumn[j], actualColumn[j]);
+                }
+            }
+        }
+    }
+
+    public void testWriteJDBCReadNDB() {
+        writeJDBCreadNDB();
+        failOnError();
+    }
+
+    public void testWriteNDBReadJDBC() {
+        writeNDBreadJDBC();
+        failOnError();
+   }
+
+   static ColumnDescriptor binary1 = new ColumnDescriptor
+            ("binary1", new InstanceHandler() {
+        public void setFieldValue(IdBase instance, Object value) {
+            ((VarbinaryTypes)instance).setBinary1((byte[])value);
+        }
+        public Object getFieldValue(IdBase instance) {
+            return ((VarbinaryTypes)instance).getBinary1();
+        }
+        public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
+                throws SQLException {
+            preparedStatement.setBytes(j, (byte[])value);
+        }
+        public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
+            return rs.getBytes(j);
+        }
+    });
+
+   static ColumnDescriptor binary2 = new ColumnDescriptor
+            ("binary2", new InstanceHandler() {
+        public void setFieldValue(IdBase instance, Object value) {
+            ((VarbinaryTypes)instance).setBinary2((byte[])value);
+        }
+        public Object getFieldValue(IdBase instance) {
+            return ((VarbinaryTypes)instance).getBinary2();
+        }
+        public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
+                throws SQLException {
+            preparedStatement.setBytes(j, (byte[])value);
+        }
+        public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
+            return rs.getBytes(j);
+        }
+    });
+
+   static ColumnDescriptor binary4 = new ColumnDescriptor
+            ("binary4", new InstanceHandler() {
+        public void setFieldValue(IdBase instance, Object value) {
+            ((VarbinaryTypes)instance).setBinary4((byte[])value);
+        }
+        public Object getFieldValue(IdBase instance) {
+            return ((VarbinaryTypes)instance).getBinary4();
+        }
+        public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
+                throws SQLException {
+            preparedStatement.setBytes(j, (byte[])value);
+        }
+        public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
+            return rs.getBytes(j);
+        }
+    });
+
+   static ColumnDescriptor binary8 = new ColumnDescriptor
+            ("binary8", new InstanceHandler() {
+        public void setFieldValue(IdBase instance, Object value) {
+            ((VarbinaryTypes)instance).setBinary8((byte[])value);
+        }
+        public Object getFieldValue(IdBase instance) {
+            return ((VarbinaryTypes)instance).getBinary8();
+        }
+        public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
+                throws SQLException {
+            preparedStatement.setBytes(j, (byte[])value);
+        }
+        public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
+            return rs.getBytes(j);
+        }
+    });
+
+    static ColumnDescriptor binary16 = new ColumnDescriptor
+            ("binary16", new InstanceHandler() {
+        public void setFieldValue(IdBase instance, Object value) {
+            ((VarbinaryTypes)instance).setBinary16((byte[])value);
+        }
+        public Object getFieldValue(IdBase instance) {
+            return ((VarbinaryTypes)instance).getBinary16();
+        }
+        public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
+                throws SQLException {
+            preparedStatement.setBytes(j, (byte[])value);
+        }
+        public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
+            return rs.getBytes(j);
+        }
+    });
+
+    static ColumnDescriptor binary32 = new ColumnDescriptor
+            ("binary32", new InstanceHandler() {
+        public void setFieldValue(IdBase instance, Object value) {
+            ((VarbinaryTypes)instance).setBinary32((byte[])value);
+        }
+        public Object getFieldValue(IdBase instance) {
+            return ((VarbinaryTypes)instance).getBinary32();
+        }
+        public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
+                throws SQLException {
+            preparedStatement.setBytes(j, (byte[])value);
+        }
+        public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
+            return rs.getBytes(j);
+        }
+    });
+
+    static ColumnDescriptor binary64 = new ColumnDescriptor
+            ("binary64", new InstanceHandler() {
+        public void setFieldValue(IdBase instance, Object value) {
+            ((VarbinaryTypes)instance).setBinary64((byte[])value);
+        }
+        public Object getFieldValue(IdBase instance) {
+            return ((VarbinaryTypes)instance).getBinary64();
+        }
+        public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
+                throws SQLException {
+            preparedStatement.setBytes(j, (byte[])value);
+        }
+        public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
+            return rs.getBytes(j);
+        }
+    });
+
+    static ColumnDescriptor binary128 = new ColumnDescriptor
+        ("binary128", new InstanceHandler() {
+            public void setFieldValue(IdBase instance, Object value) {
+                ((VarbinaryTypes)instance).setBinary128((byte[])value);
+             }
+             public Object getFieldValue(IdBase instance) {
+                return ((VarbinaryTypes)instance).getBinary128();
+             }
+             public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
+                    throws SQLException {
+                preparedStatement.setBytes(j, (byte[])value);
+             }
+             public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
+                return rs.getBytes(j);
+        }
+    });
+
+    static ColumnDescriptor binary256 = new ColumnDescriptor
+       ("binary256", new InstanceHandler() {
+           public void setFieldValue(IdBase instance, Object value) {
+               ((VarbinaryTypes)instance).setBinary256((byte[])value);
+            }
+            public Object getFieldValue(IdBase instance) {
+               return ((VarbinaryTypes)instance).getBinary256();
+            }
+            public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
+                   throws SQLException {
+               preparedStatement.setBytes(j, (byte[])value);
+            }
+            public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
+               return rs.getBytes(j);
+        }
+    });
+
+    static ColumnDescriptor binary512 = new ColumnDescriptor
+        ("binary512", new InstanceHandler() {
+            public void setFieldValue(IdBase instance, Object value) {
+                ((VarbinaryTypes)instance).setBinary512((byte[])value);
+             }
+             public Object getFieldValue(IdBase instance) {
+                return ((VarbinaryTypes)instance).getBinary512();
+             }
+             public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
+                    throws SQLException {
+                preparedStatement.setBytes(j, (byte[])value);
+             }
+             public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
+                return rs.getBytes(j);
+        }
+    });
+
+    static ColumnDescriptor binary1024 = new ColumnDescriptor
+        ("binary1024", new InstanceHandler() {
+            public void setFieldValue(IdBase instance, Object value) {
+                ((VarbinaryTypes)instance).setBinary1024((byte[])value);
+             }
+             public Object getFieldValue(IdBase instance) {
+                return ((VarbinaryTypes)instance).getBinary1024();
+             }
+             public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
+                    throws SQLException {
+                preparedStatement.setBytes(j, (byte[])value);
+             }
+             public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
+                return rs.getBytes(j);
+         }
+     });
+
+    static ColumnDescriptor binary2048 = new ColumnDescriptor
+        ("binary2048", new InstanceHandler() {
+            public void setFieldValue(IdBase instance, Object value) {
+                ((VarbinaryTypes)instance).setBinary2048((byte[])value);
+             }
+             public Object getFieldValue(IdBase instance) {
+                return ((VarbinaryTypes)instance).getBinary2048();
+             }
+             public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
+                    throws SQLException {
+                preparedStatement.setBytes(j, (byte[])value);
+             }
+             public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
+                return rs.getBytes(j);
+        }
+    });
+
+    protected static ColumnDescriptor[] columnDescriptors = new ColumnDescriptor[] {
+            binary1,
+            binary2,
+            binary4,
+            binary8,
+            binary16,
+            binary32,
+            binary64,
+            binary128,
+            binary256,
+            binary512,
+            binary1024,
+            binary2048
+        };
+
+    @Override
+    protected ColumnDescriptor[] getColumnDescriptors() {
+        return columnDescriptors;
+    }
+
+}

=== added file 'storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/model/VarbinaryTypes.java'
--- a/storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/model/VarbinaryTypes.java	1970-01-01 00:00:00 +0000
+++ b/storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/model/VarbinaryTypes.java	2011-02-04 22:14:36 +0000
@@ -0,0 +1,101 @@
+/*
+ *  Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+*/
+
+package testsuite.clusterj.model;
+
+import com.mysql.clusterj.annotation.PersistenceCapable;
+import com.mysql.clusterj.annotation.PrimaryKey;
+
+/** Schema
+ *
+drop table if exists varbinarytypes;
+create table varbinarytypes (
+ id int not null primary key,
+
+ binary1 varbinary(1),
+ binary2 varbinary(2),
+ binary4 varbinary(4),
+ binary8 varbinary(8),
+ binary16 varbinary(16),
+ binary32 varbinary(32),
+ binary64 varbinary(64),
+ binary128 varbinary(128),
+ binary256 varbinary(256),
+ binary512 varbinary(512),
+ binary1024 varbinary(1024),
+ binary2048 varbinary(2048)
+
+) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
+
+ */
+
+@PersistenceCapable(table="varbinarytypes")
+@PrimaryKey(column="id")
+public interface VarbinaryTypes extends IdBase {
+
+    int getId();
+    void setId(int id);
+
+    // Byte Array
+    byte[] getBinary1();
+    void setBinary1(byte[] value);
+
+    // Byte Array
+    byte[] getBinary2();
+    void setBinary2(byte[] value);
+
+    // Byte Array
+    byte[] getBinary4();
+    void setBinary4(byte[] value);
+
+    // Byte Array
+    byte[] getBinary8();
+    void setBinary8(byte[] value);
+
+    // Byte Array
+    byte[] getBinary16();
+    void setBinary16(byte[] value);
+
+    // Byte Array
+    byte[] getBinary32();
+    void setBinary32(byte[] value);
+
+    // Byte Array
+    byte[] getBinary64();
+    void setBinary64(byte[] value);
+
+    // Byte Array
+    byte[] getBinary128();
+    void setBinary128(byte[] value);
+
+    // Byte Array
+    byte[] getBinary256();
+    void setBinary256(byte[] value);
+
+    // Byte Array
+    byte[] getBinary512();
+    void setBinary512(byte[] value);
+
+    // Byte Array
+    byte[] getBinary1024();
+    void setBinary1024(byte[] value);
+
+    // Byte Array
+    byte[] getBinary2048();
+    void setBinary2048(byte[] value);
+
+}

=== modified file 'storage/ndb/clusterj/clusterj-test/src/main/resources/schema.sql'
--- a/storage/ndb/clusterj/clusterj-test/src/main/resources/schema.sql	2011-02-03 14:37:50 +0000
+++ b/storage/ndb/clusterj/clusterj-test/src/main/resources/schema.sql	2011-02-04 22:14:36 +0000
@@ -83,6 +83,25 @@ create table binarytypes (
 
 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
 
+drop table if exists varbinarytypes;
+create table varbinarytypes (
+ id int not null primary key,
+
+ binary1 varbinary(1),
+ binary2 varbinary(2),
+ binary4 varbinary(4),
+ binary8 varbinary(8),
+ binary16 varbinary(16),
+ binary32 varbinary(32),
+ binary64 varbinary(64),
+ binary128 varbinary(128),
+ binary256 varbinary(256),
+ binary512 varbinary(512),
+ binary1024 varbinary(1024),
+ binary2048 varbinary(2048)
+
+) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
+
 drop table if exists charsetlatin1;
 create table charsetlatin1 (
  id int not null primary key,

=== modified file 'storage/ndb/clusterj/clusterj-tie/src/main/java/com/mysql/clusterj/tie/ColumnImpl.java'
--- a/storage/ndb/clusterj/clusterj-tie/src/main/java/com/mysql/clusterj/tie/ColumnImpl.java	2011-02-02 09:52:33 +0000
+++ b/storage/ndb/clusterj/clusterj-tie/src/main/java/com/mysql/clusterj/tie/ColumnImpl.java	2011-02-04 22:14:36 +0000
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ *  Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -198,8 +198,6 @@ class ColumnImpl implements Column {
             case ColumnConst.Type.Longvarbinary:
                 this.prefixLength = 2;
                 this.columnSpace = alignTo4(length + prefixLength);
-                this.charsetNumber = ndbColumn.getCharsetNumber();
-                mapCharsetName();
                 break;
             case ColumnConst.Type.Time:
                 this.prefixLength = 0;

=== added file 'storage/ndb/clusterj/clusterj-tie/src/test/java/testsuite/clusterj/tie/VarbinaryTypesTest.java'
--- a/storage/ndb/clusterj/clusterj-tie/src/test/java/testsuite/clusterj/tie/VarbinaryTypesTest.java	1970-01-01 00:00:00 +0000
+++ b/storage/ndb/clusterj/clusterj-tie/src/test/java/testsuite/clusterj/tie/VarbinaryTypesTest.java	2011-02-04 22:14:36 +0000
@@ -0,0 +1,22 @@
+/*
+ *  Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+*/
+
+package testsuite.clusterj.tie;
+
+public class VarbinaryTypesTest extends testsuite.clusterj.VarbinaryTypesTest {
+
+}


Attachment: [text/bzr-bundle] bzr/craig.russell@oracle.com-20110204221436-hjc8o4u2za9oeq21.bundle
Thread
bzr commit into mysql-5.1-telco-7.1 branch (Craig.Russell:4083) Bug#59941Craig L Russell4 Feb