Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-955

ArrayIndexOutOfBoundsException when using "SELECT EXISTS" with a long string argument

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Duplicate
    • 3.0.4
    • 3.0.5
    • Other
    • None
    • MySQL 5.7.37

    Description

      When we run SQL queries with "SELECT EXISTS" with a long string parameter, it will throw exceptions like:

      java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 302
      	at org.mariadb.jdbc.client.impl.StandardReadableByteBuf.readShort(StandardReadableByteBuf.java:141)
      	at org.mariadb.jdbc.message.server.ColumnDefinitionPacket.<init>(ColumnDefinitionPacket.java:106)
      	at org.mariadb.jdbc.message.ClientMessage.readPacket(ClientMessage.java:198)
      	at org.mariadb.jdbc.client.impl.StandardClient.readPacket(StandardClient.java:815)
      	at org.mariadb.jdbc.client.impl.StandardClient.readResults(StandardClient.java:754)
      	at org.mariadb.jdbc.client.impl.StandardClient.readResponse(StandardClient.java:673)
      	at org.mariadb.jdbc.client.impl.StandardClient.execute(StandardClient.java:616)
      	at org.mariadb.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:93)
      	at org.mariadb.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:276)
      	at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:122)
      	at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:122)
      

      Steps to reproduce the issue:
      1. Create the table:

      CREATE TABLE test (
        field varchar(300) NOT NULL
      );
      

      2. Java code to reproduce the issue:

          ...
          Connection conn = dataSource.getConnection();
          StringBuilder sb = new StringBuilder();
          String sQuery = "SELECT EXISTS (SELECT 1 FROM test WHERE ((field=?)))";
          for (int i = 1; i <= 300; i++) {
            sb.append("a");
            if (i < 204) {
              continue;
            }
            PreparedStatement stmt = conn.prepareStatement(sQuery);
            stmt.setString(1, sb.toString());
            try {
              ResultSet rset = stmt.executeQuery();
              rset.close();
            }
            catch (Exception e) {
              System.out.println("Error " + e.getMessage() + " when i=" + i);
              e.printStackTrace();
              break;
            }
            finally {
              stmt.close();
            }
          }
          conn.close();
      

      Exceptions are thrown when the string size is 205.
      The issue only occurs when "SELECT EXISTS" is used.

      Attachments

        Issue Links

          Activity

            People

              diego dupin Diego Dupin
              raymondchen625 Raymond Chen
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.