Connector/J: malicious server crashes client JVM via unbounded result-set field-count allocation in ClientMessage.readPacket
The MariaDB Connector/J driver reads the result-set column count from the server as an unbounded integer and uses it directly to size a Java array. A malicious or on-path server can send a tiny packet declaring a huge field count, causing the client JVM to run out of memory and crash.
- Triaged in 6 days
- Fixed in 37 days
- Disclosed after 2 months
MariaDB Connector/J parses result-set responses by reading the column count as a length-encoded integer straight from the wire and immediately uses it to size a Java array (new ColumnDecoder[fieldCount]) with no upper bound. A malicious or MITM MariaDB server can reply to any query - or to the driver's own connection-setup query - with a ~10-byte packet declaring a field count of up to 2^31-1, causing the client JVM to attempt a multi-gigabyte allocation and die with java.lang.OutOfMemoryError. The crash is JVM-wide, taking down all pooled connections and application threads.
Root cause
src/main/java/org/mariadb/jdbc/message/ClientMessage.java:
default:
int fieldCount = buf.readIntLengthEncodedNotNull(); // line 282: server-controlled
ColumnDecoder[] ci;
if (context.canSkipMeta() && this.canSkipMeta()) {
...
} else {
ci = new ColumnDecoder[fieldCount]; // line 302: unbounded allocation
for (int i = 0; i < fieldCount; i++) { ... }
}
readIntLengthEncodedNotNull() (ReadableByteBuf.java:148) returns the wire value verbatim. For the 0xfe form it does return (int) readLong(), giving the server full control over the 32-bit integer:
fieldCount = 0x10000000(268M) ->OutOfMemoryError: Java heap spacefieldCount = 0x7fffffff->OutOfMemoryError: Requested array size exceeds VM limitfieldCount = 0xffffffff->NegativeArraySizeException
None are caught inside readPacket. OutOfMemoryError is JVM-wide - it destabilizes the entire client process.
The driver default is sslMode=DISABLE (plaintext, Configuration.java:309), so an on-path attacker can rewrite server responses without controlling the actual database.
Steps To Reproduce
Environment: OpenJDK 21, driver built from HEAD c9377bc (mariadb-java-client-3.5.9.jar).
Step 1 - Start the rogue server (rogue_server.py attached):
python3 rogue_server.py positive 0 &
The server completes a plaintext handshake, OKs the driver's setup query, then answers SELECT 1 with a result-set header declaring fieldCount = 0x10000000.
Step 2 - POSITIVE (attack) - run a standard JDBC client (OomClient.java attached):
java -Xmx256m -cp .:mariadb-java-client-3.5.9.jar OomClient "jdbc:mariadb://127.0.0.1:<port>/test?user=app&password=secret"
Output:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at org.mariadb.jdbc.message.ClientMessage.readPacket(ClientMessage.java:302)
at org.mariadb.jdbc.client.impl.StandardClient.readPacket(StandardClient.java:1438)
at org.mariadb.jdbc.client.impl.StandardClient.readResults(StandardClient.java:1377)
at org.mariadb.jdbc.Statement.executeQuery(Statement.java:137)
at OomClient.main(OomClient.java:22)
client exit code = 1
Connect-time variant (server mode connect - injects on the driver's own setup query):
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at org.mariadb.jdbc.message.ClientMessage.readPacket(ClientMessage.java:302)
at org.mariadb.jdbc.client.impl.StandardClient.postConnectionQueries(StandardClient.java:816)
at org.mariadb.jdbc.Driver.connect(Driver.java:75)
JVM dies inside DriverManager.getConnection() - no application query, no valid credentials needed.
Step 3 - NEGATIVE CONTROL (same driver, same URL, same SELECT 1, benign 1-column result):
connected; running SELECT 1
RESULT=1
CLEAN_EXIT
client exit code = 0
The only difference is the field-count value in the server's result-set header.
Supporting Material/References
- Vulnerable line:
ClientMessage.java:302(new ColumnDecoder[fieldCount]) - Same-family siblings:
Reader.java:133(unbounded accumulator),OkPacket.java:160(new byte[readIntLengthEncodedNotNull()]) - Accepted sibling: H1 #3835450 (connector-nodejs malicious-server DoS, Medium)
- Attachments:
rogue_server.py,OomClient.java,run_poc.sh,poc_evidence.txt
Impact
A malicious or MITM MariaDB server crashes the connecting client's JVM with OutOfMemoryError using a single small packet. The crash is JVM-wide - it brings down the entire client application, every pooled connection and worker thread, not just one query.
The crash fires during DriverManager.getConnection() (connect-time variant), before any application query and without valid credentials. Any service that opens a JDBC connection to an attacker-influenced endpoint - SSRF-style connection strings, MITM on a plaintext link, a compromised database host, or a hostile replica in a failover topology - is knocked over at connect time.
Preconditions: the client must open a connection whose bytes the attacker controls. The driver default is sslMode=DISABLE (plaintext), so any network-level MITM suffices. No authentication and no application-level query are required.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The driver uses a server-supplied length-encoded integer as an array size without any upper bound or validation.
Impact
A malicious or on-path server can crash the whole client JVM with a single small packet, even during connection setup and without valid credentials; the default plaintext mode means any network attacker can do this.
What the attacker needed
Attacker controls connection bytes; default plaintext sslMode=DISABLE
The fix
The driver should bound the server-supplied field count before allocating the array.
How it was found
- Start a rogue server that completes the handshake and answers a query with a huge declared field count.
- Run a standard JDBC client against that server.
- Observe the client JVM crash with an out-of-memory error.
- Repeat with a benign one-column result to confirm the client exits cleanly.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a database client talks to a server, the server first says how many columns the answer has. This driver trusted that number completely and tried to reserve memory for that many columns. A fake server can claim a gigantic number, so the program runs out of memory and stops working.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.