Bug #99108 Zero-length branch qualifier causes SQL syntax error when starting transaction

Submitted: 30 Mar 2020 14:11 Modified: 4 May 2020 12:20
Reporter: Viliam Durina Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:8.0.12 OS:Ubuntu
Assigned to: CPU Architecture:x86

[30 Mar 2020 14:11] Viliam Durina
Description:
Using JDBC we created a `Xid` with zero-length branch qualifier. When calling `XAResource.start(xid, TMNOFLAGS)`, this error was thrown:

Exception in thread "main" com.mysql.cj.jdbc.MysqlXAException: Undetermined error occurred in the underlying Connection - check your data for consistency
	at com.mysql.cj.jdbc.MysqlXAConnection.mapXAExceptionFromSQLException(MysqlXAConnection.java:347)
	at com.mysql.cj.jdbc.MysqlXAConnection.dispatchCommand(MysqlXAConnection.java:329)
	at com.mysql.cj.jdbc.MysqlXAConnection.start(MysqlXAConnection.java:290)
	at com.hazelcast.jet.contrib.xatests.JdbcXaTest.main(JdbcXaTest.java:66)
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0x,0x1' at line 1
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
	at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:764)
	at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:648)
	at com.mysql.cj.jdbc.MysqlXAConnection.dispatchCommand(MysqlXAConnection.java:323)
	... 2 more 

How to repeat:
Use this `Xid` implementation:

public final class MyXid implements Xid, Serializable {

    private final byte trId;

    /** Constructor */
    public MyXid(int trId) {
        this.trId = (byte) trId;
    }

    @Override
    public int getFormatId() {
        return 1;
    }

    @Override
    public byte[] getGlobalTransactionId() {
        return new byte[]{trId};
    }

    @Override
    public byte[] getBranchQualifier() {
        return new byte[0];
    }
}

Then call this:

        XAConnection xaConn = factory.getXAConnection();
        Connection conn = xaConn.getConnection();
        XAResource xaRes = xaConn.getXAResource();
        Xid xid = new MyXid(1);
        // here it fails:
        xaRes.start(xid, XAResource.TMNOFLAGS);

I confirmed with the X/Open spec that the branch qualifier should have length between 1..64, so 0 isn't allowed. But other databases accept it so it can happen in the wild. The above error is very unspecific and took us a while to figure out the cause. JDBC driver version was 8.0.18.

Suggested fix:
I expect the code to throw "Branch qualifier must be between 1..64 bytes" or similar.
[3 Apr 2020 12:53] MySQL Verification Team
Hi Mr. Durina,

Thank you for your bug report.

When you created this report, you have set a category of "MySQL Server: XA transactions". However, your steps for repeating this behaviour are strictly related to Connector/JDBC.

Hence, if the category is correct, you can provide us with a test case in SQL ????

Last, but not least, you are using an outdated release. Hence, please download and use latest releases of our server and of Connector/JDBC. Let us know if it helps .......
[3 Apr 2020 13:13] Viliam Durina
I couldn't find a category for JDBC driver, that's why I've put it to the XA transactions category. I don't have a reproducer in plain SQL. Can you please change the category?

Regarding the version this is the newest version I have in my setup using testcontainers. It's rather minor issue and I searched for existing issues first, I don't believe it was fixed since then, though it's possible. I'm unable to try the newest release now.
[3 Apr 2020 13:24] MySQL Verification Team
Hi Mr. Durina,

I have now set a category that is correct.

Still, we do not test reports on the old releases. Please, try our latest server and latest Connector/J release.

Thanks in advance.
[4 May 2020 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.043 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.