Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDBC: Undefined behavior when reading from a returned java.sql.Blob outside of a closed result set #99

Closed
2 tasks done
ShadelessFox opened this issue Oct 15, 2024 · 3 comments

Comments

@ShadelessFox
Copy link

ShadelessFox commented Oct 15, 2024

What happens?

Blobs retrieved from a result set before it's closed might return random values between GC calls.

To Reproduce

import java.sql.*;
import java.util.HexFormat;

public class DuckDBBlobTest {
    public static void main(String[] args) throws Exception {
        try (Connection connection = DriverManager.getConnection("jdbc:duckdb:")) {
            try (Statement stmt = connection.createStatement()) {
                Blob blob;

                try (ResultSet resultSet = stmt.executeQuery("select 'AAAA'::blob")) {
                    resultSet.next();
                    blob = resultSet.getBlob(1);
                }

                String expected = HexFormat.of().formatHex(new byte[]{'A', 'A', 'A', 'A'});
                for (int i = 0; i < 5000; i++) {
                    System.gc();
                    String actual = HexFormat.of().formatHex(blob.getBytes(0, Math.toIntExact(blob.length())));
                    if (!expected.equals(actual)) {
                        throw new SQLException("expected != actual: " + expected + " != " + actual);
                    }
                }
            }
        }
    }
}

Please note that this is a floating issue and might not reproduce immediately. Try running the sample multiple times. Eventually, you will see something like this:

expected != actual: 41414141 != 00000000

OS:

Windows 11 x64

DuckDB Version:

1.1.1

DuckDB Client:

Java JDBC / DBeaver 24.2.3

Hardware:

No response

Full Name:

Ian Vinogradov

Affiliation:

DBeaver

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a stable release

Did you include all relevant data sets for reproducing the issue?

Yes

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

  • Yes, I have
@Tishj
Copy link
Contributor

Tishj commented Oct 15, 2024

@szarnyasg can we move this to https://github.com/duckdb/duckdb-java ?

@szarnyasg szarnyasg transferred this issue from duckdb/duckdb Oct 15, 2024
@EastLord
Copy link

EastLord commented Nov 4, 2024

#79

@Mause
Copy link
Member

Mause commented Nov 7, 2024

Going to assume this is resolved by #103

@Mause Mause closed this as completed Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants