pingcap / pingcap/tidb

`runtime error: makeslice: len out of range` triggered by PREPARE with JDBC

Open
#66,012 0 comments 1 reaction 0 assignees View on GitHub
contribution fuzz/sqlancer impact/panic may-affects-7.1 may-affects-7.5 may-affects-8.1 may-affects-8.5 severity/major sig/execution type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

Hi,

The following test case triggers an error `makeslice: len out of range` only with JDBC. And have different error messages with multiple runs. I tried to reduce the test case, but can not reproduce the error with a smaller one.

This is the Java rapper:

```
import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class TiDBRunner {
public static void main(String[] args) {
String url = "jdbc:mysql://127.0.0.1:4000/?user=root&password=&allowMultiQueries=true";
String filePath = "database7r-cur.sql";

try (Connection conn = DriverManager.getConnection(url);
BufferedReader reader = new BufferedReader(new FileReader(filePath))) {

StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
String trimmedLine = line.trim();
if (trimmedLine.isEmpty() || trimmedLine.startsWith("--")) {
continue;
}
sb.append(line).append("\n");
if (trimmedLine.endsWith(";")) {
String sql = sb.toString();
executeSql(conn, sql);
sb.setLength(0);
}
}

// Execute any remaining SQL (if file doesn't end with ;)
if (sb.length() > 0 && !sb.toString().trim().isEmpty()) {
executeSql(conn, sb.toString());
}

} catch (Exception e) {
e.printStackTrace();
}
}

private static void executeSql(Connection conn, String sql) {
try (Statement stmt = conn.createStatement()) {
System.out.println("Executing: " + sql.substring(0, Math.min(sql.length(), 100)) + (sql.length() > 100 ? "..." : ""));
stmt.execute(sql);
} catch (SQLException e) {
System.err.println("Failed to execute: " + sql);
e.printStackTrace();
}
}
}

```

This is the command:

```
java -cp /root/.m2/repository/com/mysql/mysql-connector-j/8.0.33/mysql-connector-j-8.0.33.jar TiDBRunner.java
```

This is the test case:

[database7r-cur.sql](https://github.com/user-attachments/files/25060841/database7r-cur.sql)

### 2. What did you expect to see? (Required)

No error.

### 3. What did you see instead (Required)

```
err="runtime error: makeslice: len out of range\ngithub.com/pingcap/errors.Trace\n\t/root/go/pkg/mod/github.com/pingcap/errors@v0.11.5-0.20250523034308-74f78ae071ee/juju_adaptor.go:15\ngithub.com/pingcap/tidb/pkg/util.GetRecoverError\n\t/home/zhangchi/data/EPSC/tidb/pkg/util/util.go:296\ngithub.com/pingcap/tidb/pkg/executor/internal/exec.Next.func1\n\t/home/zhangchi/data/EPSC/tidb/pkg/executor/internal/exec/executor.go:444\nruntime.gopanic\n\t/root/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.6.linux-amd64/src/runtime/panic.go:783\nruntime.panicmakeslicelen\n\t/root/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.6.linux-amd64/src/runtime/slice.go:29\nruntime.makeslice\n\t/root/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.6.linux-amd64/src/runtime/slice.go:111\ngithub.com/pingcap/tidb/pkg/types.(*MyDecimal).ToString\n\t/home/zhangchi/data/EPSC/tidb/pkg/types/mydecimal.go:318\ngithub.com/pingcap/tidb/pkg/expression.(*builtinCastDecimalAsTimeSig).vecEvalTime\n\t/home/zhangchi/data/EPSC/tidb/pkg/expression/builtin_cast_vec.go:1501\ngithub.com/pingcap/tidb/pkg/expression.(*ScalarFunction).VecEvalTime\n\t/home/zhangchi/data/EPSC/tidb/pkg/expression/scalar_function.go:97\ngithub.com/pingcap/tidb/pkg/expression.(*builtinDateFormatSig).vecEvalString\n\t/home/zhangchi/data/EPSC/tidb/pkg/expression/builtin_time_vec.go:1822\ngithub.com/pingcap/tidb/pkg/expression.(*ScalarFunction).VecEvalString\n\t/home/zhangchi/data/EPSC/tidb/pkg/expression/scalar_function.go:79\ngithub.com/pingcap/tidb/pkg/expression.(*builtinCastStringAsIntSig).vecEvalInt\n\t/home/zhangchi/data/EPSC/tidb/pkg/expression/builtin_cast_vec.go:961\ngithub.com/pingcap/tidb/pkg/expression.(*ScalarFunction).VecEvalInt\n\t/home/zhangchi/data/EPSC/tidb/pkg/expression/scalar_function.go:61\ngithub.com/pingcap/tidb/pkg/expression.(*builtinRightShiftSig).vecEvalInt\n\t/home/zhangchi/data/EPSC/tidb/pkg/expression/builtin_op_vec.go:690\ngithub.com/pingcap/tidb/pkg/expression.(*ScalarFunction).VecEvalInt\n\t/home/zhangchi/data/EPSC/tidb/pkg/expression/scalar_function.go:61\ngithub.com/pingcap/tidb/pkg/expression.EvalExpr\n\t/home/zhangchi/data/EPSC/tidb/pkg/expression/expression.go:671\ngithub.com/pingcap/tidb/pkg/expression.VecEvalBool\n\t/home/zhangchi/data/EPSC/tidb/pkg/expression/expression.go:451\ngithub.com/pingcap/tidb/pkg/expression.vectorizedFilter\n\t/home/zhangchi/data/EPSC/tidb/pkg/expression/chunk_executor.go:524\ngithub.com/pingcap/tidb/pkg/expression.VectorizedFilterConsiderNull\n\t/home/zhangchi/data/EPSC/tidb/pkg/expression/chunk_executor.go:436\ngithub.com/pingcap/tidb/pkg/expression.VectorizedFilter\n\t/home/zhangchi/data/EPSC/tidb/pkg/expression/chunk_executor.go:414\ngithub.com/pingcap/tidb/pkg/executor.(*SelectionExec).Next\n\t/home/zhangchi/data/EPSC/tidb/pkg/executor/select.go:774\ngithub.com/pingcap/tidb/pkg/executor/internal/exec.Next\n\t/home/zhangchi/data/EPSC/tidb/pkg/executor/internal/exec/executor.go:460\ngithub.com/pingcap/tidb/pkg/executor/aggregate.(*HashAggExec).fetchChildData\n\t/home/zhangchi/data/EPSC/tidb/pkg/executor/aggregate/agg_hash_executor.go:503\nruntime.goexit\n\t/root/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.6.linux-amd64/src/runtime/asm_amd64.s:1693"
```

### 4. What is your TiDB version? (Required)

v9.0.0-beta.2.pre-1118-gfc6f7b2e42

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.