[CONJ-284] Cannot read autoincremented IDs bigger than Short.MAX_VALUE Created: 2016-04-21  Updated: 2016-05-03  Resolved: 2016-04-22

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 1.4.0, 1.4.1, 1.4.2
Fix Version/s: 1.4.3

Type: Bug Priority: Blocker
Reporter: Christian Ciach Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Environment:

Fedora Core 23 x64, connecting to 10.1.13-MariaDB MariaDB Server



 Description   

When inserting a new row using a PreparedStatement into a table with an auto incremented ID, the connector returns a negative ID if the actual generated ID is greater than 32767.

I've nailed this down to this method: org.mariadb.jdbc.internal.util.buffer.Buffer.getLengthEncodedBinary()

In version 1.3.7, where this still works, the method contains this snippet:

case (byte) 0xfc: //252
     return (long) 0xffff & readShort();

In version 1.4.2, where it's broken, it looks like this:

case 252:
    return readShort();

I think this bug is insanely critical.



 Comments   
Comment by Diego Dupin [ 2016-04-21 ]

After inserting a data, server return insert ids that can be accessed with Statement.getGeneratedKeys().
When this id size is on 2 bytes unsigned, the unsigned part is not well handled, due to a (short) cast, changing value to negative value if value is beetween 32767 and 65535.

Example : an insert id on 2 bytes with the 0x9c40 (40000) value will be inserted well, but driver will return a wrong value of return as id -25536.

That is indeed more than critical, priority changed to blocker. A correction will be release tomorrow.
That may be the biggest regression seen on driver ...

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