[CONJ-956] ArrayIndexOutOfBoundsException when alias length > 250 Created: 2022-04-08  Updated: 2022-05-13  Resolved: 2022-04-11

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 3.0.4
Fix Version/s: 3.0.5

Type: Bug Priority: Critical
Reporter: Brent Levinson Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Duplicate
is duplicated by CONJ-955 ArrayIndexOutOfBoundsException when u... Closed
is duplicated by CONJ-963 Cume_dist with Partition by returns e... Closed

 Description   

java.lang.ArrayIndexOutOfBoundsException: 365
at (StandardReadableByteBuf.java:133)
at org.mariadb.jdbc.message.server.ColumnDefinitionPacket.<init>(ColumnDefinitionPacket.java:78)
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.Statement.executeInternal(Statement.java:906)
at org.mariadb.jdbc.Statement.executeQuery(Statement.java:114)

Is this related to CONJ-901?



 Comments   
Comment by Brent Levinson [ 2022-04-08 ]

I have been trying random SQL work arounds, but only leads to minor shifts in the exception. See below:

java.lang.ArrayIndexOutOfBoundsException: 255
at org.mariadb.jdbc.client.impl.StandardReadableByteBuf.skipIdentifier(StandardReadableByteBuf.java:111)
at org.mariadb.jdbc.message.server.ColumnDefinitionPacket.<init>(ColumnDefinitionPacket.java:67)
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.Statement.executeInternal(Statement.java:906)
at org.mariadb.jdbc.Statement.executeQuery(Statement.java:114)

Comment by Diego Dupin [ 2022-04-11 ]

Could you help giving some additional info, to try to reproduced the issue ? like:

  • confirm this issue correspond to version 3.0.4
  • indicate server type (mysql/mariadb/xpand/maxscale ... and version)
  • could those queries concern specific DATATYPE like JSON/UUID ?
Comment by Brent Levinson [ 2022-04-11 ]

This is a query against MariaDB 10.5.7
The SQL is a Select Case, with two sub-Selects
It is replicated only within a large transaction (i.e. it cannot be replicated with a single SQL operation).
It does not occur using any MySQL Connector/J 5 or 8 versions.
We have not tested this with any other MariaDB Connector/J 3 version as 3.0.4 is the first to fix a LiquiBase issue that we have been waiting for.
I have asked internally to run a further test using the MariaDB Connector/J 2.7.5 driver and I should have a some result today.
The query does not involve JSON/UUID, here is sample SQL:
SELECT ifnull((select case data_string when 'S' then 1 when 'U' then 0 end from data_master where record_id = (select record_id from record_master where unit_id = 67010 and case_id = '2021ANG0410' and win_id = (select win_id from wins_master where schedule = 'DEC')) and field_id = (select field_id from field_master where field_name = 'approval_status')),0)

Comment by Diego Dupin [ 2022-04-11 ]

I would seem more a server issue than connectors.
Since it seems you can reproduce the problem, Is it possible to have wireshark log data that concern the moment where it fails ?

Comment by Brent Levinson [ 2022-04-11 ]

How can it be a server issue when the MySQL connector works, but the MariaDB connector does not?
I have no indication of an error in the MariaDB server log.
I can work on capturing a trace log.

Comment by Brent Levinson [ 2022-04-11 ]

Thank you, I appreciate your research. I have looking at Wireshark results and not seeing anything. Our test of the 2.7 driver was unsuccessful because it has other limitations that prevent us from using it.

Does that mean we could restructure our SQL and provide an alias to the sub-selects as a work around? Or is their a configuration on the MariaDB server to limit the size of server generated aliases?

Comment by Diego Dupin [ 2022-04-11 ]

Aliases are limited to 256 characters.
This occurs when column aliases length is > 250.

Aliases value are length encoded, and current implementation was expecting only 1 or 3 bytes length encoded prefix. Some queries might return a 9 byte length prefix even for a 251 length alias.

This will be corrected in next release

Comment by Diego Dupin [ 2022-04-11 ]

Correction is available using snapshot:

<repositories>
    <repository>
        <id>sonatype-nexus-snapshots</id>
        <name>Sonatype Nexus Snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
</repositories>
 
<dependencies>
    <dependency>
        <groupId>org.mariadb.jdbc</groupId>
        <artifactId>mariadb-java-client</artifactId>
        <version>3.0.5-SNAPSHOT</version>
    </dependency>
</dependencies>

Generated at Thu Feb 08 03:19:33 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.