Skip to content

Commit

Permalink
Fix for Bug#101054 (Bug#32544786), Batched Query > maxAllowedPacket s…
Browse files Browse the repository at this point in the history
…ize causes an ArrayIndexOutOfBoundsException.

Change-Id: I3654ef343c4b7eed3ee94c263ee151197fa7fb9c
  • Loading branch information
Axyoan Marcelo committed Sep 10, 2024
1 parent 1b317cf commit 288db53
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Version 9.1.0

- Fix for Bug#101054 (Bug#32544786), Batched Query > maxAllowedPacket size causes an ArrayIndexOutOfBoundsException.

- Fix for Bug#108415 (Bug#34579258), NullPointerException in AbstractQuery::stopQueryTimer.
Thanks to Anthony Milbourne for his contribution.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ private long[] executeBatchUsingMultiQueries(boolean multiQueriesEnabled, int nb
for (commandIndex = 0; commandIndex < nbrCommands; commandIndex++) {
String nextQuery = (String) this.query.getBatchedArgs().get(commandIndex);

if (((queryBuf.length() + nextQuery.length()) * numberOfBytesPerChar + 1 /* for semicolon */
if (queryBuf.length() > 0 && ((queryBuf.length() + nextQuery.length()) * numberOfBytesPerChar + 1 /* for semicolon */
+ NativeConstants.HEADER_LENGTH) * escapeAdjust + 32 > this.maxAllowedPacket.getValue()) {
try {
batchStmt.execute(queryBuf.toString(), java.sql.Statement.RETURN_GENERATED_KEYS);
Expand Down
35 changes: 34 additions & 1 deletion src/test/java/testsuite/regression/StatementRegressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13829,4 +13829,37 @@ void testBug108415() throws Exception {
execServ.shutdown();
}

}
/**
* Tests fix for Bug#101054 (Bug#32544786), Batched Query > maxAllowedPacket size causes an ArrayIndexOutOfBoundsException.
*
* @throws Exception
*/
@Test
public void testBug101054() throws Exception {
boolean allowMQ = false;
createTable("testBug101054", "(c0 VARCHAR(2048) NOT NULL)");
do {
Properties props = new Properties();
props.setProperty(PropertyKey.allowMultiQueries.getKeyName(), Boolean.toString(allowMQ));
props.setProperty(PropertyKey.characterEncoding.getKeyName(), "utf8");
props.setProperty(PropertyKey.maxAllowedPacket.getKeyName(), "1024");

try (Connection testConn = getConnectionWithProps(props)) {
this.stmt = testConn.createStatement();

final String valueToInsert = new String(new char[512]).replace('\0', 'X');
final String sql = String.format("INSERT INTO testBug101054 VALUES ('%s')", valueToInsert);
final String testCase = String.format("Case [allowMQ: %s]", allowMQ ? "Y" : "N");

this.stmt.addBatch(sql);
assertDoesNotThrow(this.stmt::executeBatch, testCase);

this.rs = this.stmt.executeQuery("SELECT * FROM testBug101054");
while (this.rs.next()) {
assertEquals(valueToInsert, this.rs.getString(1), testCase);
}
}
} while (allowMQ = !allowMQ);
}

}

0 comments on commit 288db53

Please sign in to comment.