Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
Fixes issue with certain blob data columns
Browse files Browse the repository at this point in the history
Fixed an issue where if a blob column had an empty string, the query packet response processor would misinterpret a byte equalling 0x00 as a MySQL EOF packet and therefore corrupting and not retrieving all rows within the table.
  • Loading branch information
Chris Board committed Jun 12, 2020
1 parent 4ea4b2b commit 0f0416f
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 11 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
45 changes: 45 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions AndroidMySQLConnector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ else
}

archivesBaseName="AndroidMySQLConnector"
version '0.39'
version '0.40'
group 'com.BoardiesITSolutions'


Expand All @@ -30,8 +30,8 @@ android {
//applicationId "com.BoardiesITSolutions.AndroidMySQLConnector"
minSdkVersion 19
targetSdkVersion 29
versionCode 27
versionName "0.37"
versionCode 28
versionName "0.40"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.BoardiesITSolutions.AndroidMySQLConnector;

import java.math.BigInteger;

import static java.lang.Math.abs;

public class ColumnDefinition
{
public enum ColumnType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public MySQLRow()
this.columnAndRowValue = new HashMap<>();
}

public int getSizeOfHash()
{
return this.columnAndRowValue.size();
}

public void addRowValue(ColumnDefinition columnDefinition, String rowValue)
{
this.columnAndRowValue.put(columnDefinition, rowValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private void processPacketData()

int columnLength = this.mysqlConn.getMysqlIO().fromByteArray((byte[])this.mysqlConn.getMysqlIO().extractData(4));

int columnType = (byte)this.mysqlConn.getMysqlIO().extractData(1);
int columnType = (byte)this.mysqlConn.getMysqlIO().extractData(1) & 0xff;

int flags = this.mysqlConn.getMysqlIO().fromByteArray((byte[])this.mysqlConn.getMysqlIO().extractData(2));

Expand Down Expand Up @@ -155,7 +155,7 @@ private void processPacketData()
for (; currentColumn < numberOfFields; currentColumn++)
{
packetType = this.mysqlConn.getMysqlIO().readCurrentByteWithoutShift() & 0xff;
if (Helpers.getMySQLPacketTypeFromIntWithoutShift(packetType) == Helpers.MYSQL_PACKET_TYPE.MYSQL_OK_PACKET ||
if ((numberOfFields == currentColumn-1) && Helpers.getMySQLPacketTypeFromIntWithoutShift(packetType) == Helpers.MYSQL_PACKET_TYPE.MYSQL_OK_PACKET ||
Helpers.getMySQLPacketTypeFromIntWithoutShift(packetType) == Helpers.MYSQL_PACKET_TYPE.MYSQL_EOF_PACKET)
{

Expand All @@ -164,10 +164,14 @@ private void processPacketData()
//We've got an EOF packet and the remaining data in the socket data is less than 9 so this is a true 0xFE.
//You sometimes get an 0xFE packet when its actually a len encoded integer. As this is a true EOF packet
//we can break from the loop as we have everything we need
finishedProcessingColumns = true;

//We've created a row object in case we needed it, but as we've detected as an EOF packet,
//set the row to null so it doesn't get added to to the resultset.
row = null;
if (row.getSizeOfHash() == 0)
{
row = null;
finishedProcessingColumns = true;
}
break;
}
//We've got an EOF packet but there's actually more data so not a true EOF packet so shift 9 bytes
Expand All @@ -181,8 +185,11 @@ private void processPacketData()
{
if ((this.mysqlConn.getMysqlIO().getSocketDataLength() - this.mysqlConn.getMysqlIO().getCurrentBytesRead()) < 9)
{
finishedProcessingColumns = true;
row = null;
if (row.getSizeOfHash() == 0)
{
row = null;
finishedProcessingColumns = true;
}
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
buildscript {

ext {
publishToMavenLocal = false
publishToMavenLocal = true
}

repositories {
Expand Down

0 comments on commit 0f0416f

Please sign in to comment.