Bug #116119 | use onnector-c++ 9.0.0 to save base64 data to blob column, segment fault occur | ||
---|---|---|---|
Submitted: | 16 Sep 2024 11:24 | Modified: | 18 Sep 2024 9:08 |
Reporter: | jun zhang | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | Connector / C++ | Severity: | S3 (Non-critical) |
Version: | OS: | Ubuntu | |
Assigned to: | CPU Architecture: | x86 | |
Tags: | mysql connector c++ 9.0.0, sql::PreparedStatement::setBlob |
[16 Sep 2024 11:24]
jun zhang
[16 Sep 2024 12:47]
MySQL Verification Team
HI Mr. zhang, Thank you for your bug report. However, there are many facts missing from your report that disables us from repeating your test case. First of all, we need the entire C++ code that leads to the error. Entire C++ code, so that we can compile it, run it and see for ourselves. We require the image that leads to the error. Also, we do not know what is crashing in this bug. Your program or MySQL server ???? If it is MySQL server, then you can just send SQL variant that does the same thing. Next, You are using MySQL 9.00, while the current release is 9.0.1. Please, try that one. We also need to know whether C/C++ is the same version as MySQL server. Last, but not least, we need to know whether latest releases of MySQL 8.0 and 8.4 are also affected. Thank you very much in advance for your full and comprehensive answers ....... Can't repeat.
[18 Sep 2024 0:31]
Bogdan Degtyariov
According to the bug description the data length is ~2Mb, but BLOB column in MySQL can hold only 65535 bytes. It will not work the way you intended. After modifying column to MEDIUMBLOB the insert went fine. Another consideration is the change in MySQL network protocol. Due to protocol incompatibility (which by the way was introduced in version 8.4) it is expected that MySQL Connector/C++ 8.4/9.0 fails to do certain operations on MySQL 8.1, 8.2 and 8.3 servers. The issue is around prepared statement being executed. MySQL network protocol and C API for Prepared Statements are using a new function mysql_stmt_bind_named_param() instead of mysql_stmt_bind_param(). The issues are expected with non-GA versions of the MySQL Server. However, since 8.0.X is still GA + Long Term Supported, it received the protocol updates and MySQL Connector/C++ 9.X works fine with it. Test code: void connection::check_bug() { logMsg("connection::getClientInfo() - MySQL_Connection::getClientInfo()"); try { stmt.reset(con->createStatement()); stmt->executeUpdate("DROP TABLE IF EXISTS imageTable"); stmt->executeUpdate("CREATE TABLE IF NOT EXISTS imageTable(" "IMAGEID INT AUTO_INCREMENT PRIMARY KEY," "TIMESTAMP VARCHAR(255)," "IMAGE MEDIUMBLOB);"); pstmt.reset(con->prepareStatement("insert into imageTable (timestamp, image) values(?, ?)")); pstmt->setString(1, "2024-09-18 10:02:22"); std::ifstream imageFile("/home/dbs/Pictures/wallpaper.jpg", std::ios::binary); std::string fileContents((std::istreambuf_iterator<char>(imageFile)), std::istreambuf_iterator<char>()); imageFile.close(); std::istringstream blobStream(fileContents); pstmt->setBlob(2, &blobStream); pstmt->executeUpdate(); } catch (sql::SQLException &e) { logErr(e.what()); logErr("SQLState: " + std::string(e.getSQLState())); fail(e.what(), __FILE__, __LINE__); } }