Skip to content

Commit

Permalink
[CONJ-975] ArrayIndexOutOfBoundsException using Resultset.getTime() o…
Browse files Browse the repository at this point in the history
…n '00:00:00' Time value using binary protocol
  • Loading branch information
rusher committed May 25, 2022
1 parent e6a29d0 commit e3fd97f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/main/java/org/mariadb/jdbc/plugin/codec/TimeCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public Time decodeBinary(ReadableByteBuf buf, int length, Column column, Calenda
throws SQLDataException {

Calendar cal = calParam == null ? Calendar.getInstance() : calParam;
long dayOfMonth;
long dayOfMonth = 0;
int hour = 0;
int minutes = 0;
int seconds = 0;
Expand Down Expand Up @@ -151,14 +151,17 @@ public Time decodeBinary(ReadableByteBuf buf, int length, Column column, Calenda
}
return t;
case TIME:
// specific case for TIME, to handle value not in 00:00:00-23:59:59
boolean negate = buf.readByte() == 1;
dayOfMonth = buf.readUnsignedInt();
hour = buf.readByte();
minutes = buf.readByte();
seconds = buf.readByte();
if (length > 8) {
microseconds = buf.readUnsignedInt();
boolean negate = false;
if (length > 0) {
// specific case for TIME, to handle value not in 00:00:00-23:59:59
negate = buf.readByte() == 1;
dayOfMonth = buf.readUnsignedInt();
hour = buf.readByte();
minutes = buf.readByte();
seconds = buf.readByte();
if (length > 8) {
microseconds = buf.readUnsignedInt();
}
}
int offset = cal.getTimeZone().getOffset(0);
long timeInMillis =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public void getObject(ResultSet rs) throws SQLException {
assertFalse(rs.wasNull());
assertNull(rs.getTime(4));
assertTrue(rs.wasNull());
rs.next();
assertEquals(Time.valueOf("00:00:00").getTime(), rs.getTime(3).getTime());
}

@Test
Expand Down

0 comments on commit e3fd97f

Please sign in to comment.