connectivity/source/drivers/mysqlc/mysqlc_general.cxx | 3 connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.cxx | 32 +++++++++- 2 files changed, 33 insertions(+), 2 deletions(-)
New commits: commit 0dec041cb8156afb4d022d94c4c6a1d9fa222f91 Author: Julien Nabet <serval2...@yahoo.fr> AuthorDate: Mon Jan 3 21:19:56 2022 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Mon Jan 10 16:56:48 2022 +0100 tdf#146432: fix crash with REGEXP_REPLACE() executed in query editor to MariaDB See bt here: https://bugs.documentfoundation.org/attachment.cgi?id=177292 Noticing: warn:legacy.osl:7697:7697:connectivity/source/drivers/mysqlc/mysqlc_general.cxx:188: mysqlToOOOType: unhandled case, falling back to VARCHAR I found REGEXP_REPLACE returned a MYSQL_TYPE_LONG_BLOB and some locations should be taught about it. Also, let's also deal with MYSQL_TYPE_TINY_BLOB and MYSQL_TYPE_MEDIUM_BLOB Change-Id: Ib7fd6ef747ce1b1851c788d2bb5a1d4ec673aee1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127919 (cherry picked from commit e43573aae0fa07d170fb042b7184156c851c1f77) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127952 Reviewed-by: Lionel Mamane <lio...@mamane.lu> Tested-by: Jenkins Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128220 diff --git a/connectivity/source/drivers/mysqlc/mysqlc_general.cxx b/connectivity/source/drivers/mysqlc/mysqlc_general.cxx index 878efdc3be24..c56bef962c7d 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_general.cxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_general.cxx @@ -163,6 +163,9 @@ sal_Int32 mysqlToOOOType(int eType, int charsetnr) noexcept return css::sdbc::DataType::VARCHAR; case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_TINY_BLOB: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_LONG_BLOB: if (charsetnr == 63) return css::sdbc::DataType::LONGVARBINARY; return css::sdbc::DataType::LONGVARCHAR; diff --git a/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.cxx b/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.cxx index 22f5499ea9a2..0c4dba0559d5 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.cxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.cxx @@ -106,12 +106,24 @@ bool OPreparedResultSet::fetchResult() } for (sal_Int32 i = 0; i < m_nColumnCount; ++i) { + bool bIsBlobType = false; + switch (m_aFields[i].type) + { + case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_TINY_BLOB: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_LONG_BLOB: + bIsBlobType = true; + break; + default: + bIsBlobType = false; + } m_aMetaData[i].is_null = false; m_aMetaData[i].length = 0l; m_aMetaData[i].error = false; m_aData[i].is_null = &m_aMetaData[i].is_null; - m_aData[i].buffer_length = m_aFields[i].type == MYSQL_TYPE_BLOB ? 0 : m_aFields[i].length; + m_aData[i].buffer_length = bIsBlobType ? 0 : m_aFields[i].length; m_aData[i].length = &m_aMetaData[i].length; m_aData[i].error = &m_aMetaData[i].error; m_aData[i].buffer = nullptr; @@ -303,8 +315,21 @@ template <> OUString OPreparedResultSet::retrieveValue(sal_Int32 column) { // redirect call to the appropriate method if needed // BLOB can be simply read out as string + bool bIsBlobType = false; + switch (m_aFields[column - 1].type) + { + case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_TINY_BLOB: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_LONG_BLOB: + bIsBlobType = true; + break; + default: + bIsBlobType = false; + } + if (getTypeFromMysqlType(m_aFields[column - 1].type) != std::type_index(typeid(OUString)) - && m_aFields[column - 1].type != MYSQL_TYPE_BLOB) + && !bIsBlobType) return getRowSetValue(column); const char* sStr = static_cast<const char*>(m_aData[column - 1].buffer); @@ -341,6 +366,9 @@ ORowSetValue OPreparedResultSet::getRowSetValue(sal_Int32 nColumnIndex) case MYSQL_TYPE_NEWDECIMAL: return getString(nColumnIndex); case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_TINY_BLOB: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_LONG_BLOB: throw SQLException("Column with type BLOB cannot be converted", *this, "22000", 1, Any()); default: