[CONJ-1145] Wrong sequence number of sub header with compressing procotol active Created: 2024-01-04  Updated: 2024-01-12  Resolved: 2024-01-12

Status: Closed
Project: MariaDB Connector/J
Component/s: protocol
Affects Version/s: 2.7.11
Fix Version/s: 2.7.12

Type: Bug Priority: Minor
Reporter: Zhe Huang Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Environment:

MariaDB Java Connector 2.X


Attachments: PNG File 2X.png     PNG File 3X.png     PNG File source.png    

 Description   

MariaDB Java Connecter 2.X may generate wrong sequence number for the sub header.

It can be reproduced by the following code:

import java.sql.*;
 
public class Main {
    public static void main(String[] args) {
        String url = "jdbc:mariadb://127.0.0.1:4000/test?useCompression=True";
        String user = "root";
        String password = "";
 
        try {
            Connection c = DriverManager.getConnection(url, user, password);
 
            Statement s = c.createStatement();
 
            String sql = "-- :: userIDaebcda5cb52dc741f20fe495327ddbfc8411cc53663eec3a5ffdb1f30626d39cc606822\nselect version();";
            s.execute(sql);
            s.close();
            c.close();
 
        } catch (SQLException e) {
            e.printStackTrace();
        }
 
    }
}

For version 2.X, it produces the following packet with sub header: 66 00 00 01

And for version 3.X, the sub header looks like: 66 00 00 00

The sequence number of sub header should be 0 in fact. Fortunately, MySQL / MariaDB don't take this number seriously and just skip the check process. Thus it can work as normal.

However, for some other databases that follow MySQL protocol with a stricter sequence check, this would cause a problem.



 Comments   
Comment by Zhe Huang [ 2024-01-04 ]

The problem comes from the CompressPacketOutputStream.java. I used version 2.7.11 source code here.

In line 163, the sub header has been generated. Here the sequence number got increased.

Then, the compress length is so high that it does not pass the ratio(0.9) check in line 171. The process continues and it got increased again in line 278, leads th the 01 sequence number.

Comment by Zhe Huang [ 2024-01-05 ]

Also I have submitted the pull request here: https://github.com/mariadb-corporation/mariadb-connector-j/pull/191

Comment by Diego Dupin [ 2024-01-12 ]

confirmed. This concerns only 2.x version.
PR https://github.com/mariadb-corporation/mariadb-connector-j/pull/191 merged.

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