From 053bd80d43b9ad86bef43c0d78d183714b37de51 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 23 Oct 2024 20:56:12 +0200 Subject: [PATCH] MDEV-35230 ASAN errors upon reading from joined temptable views with vector type fix Field_vector::get_copy_func() for the case when length_bytes differ fix do_copy_vec() to not guess length_bytes but take it from the field (for keys length_bytes is always 2 for any length) --- mysql-test/main/vector2.result | 12 ++++++++++++ mysql-test/main/vector2.test | 10 ++++++++++ sql/sql_type_vector.cc | 7 ++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/mysql-test/main/vector2.result b/mysql-test/main/vector2.result index 798d09dccad..ecb8d8d999b 100644 --- a/mysql-test/main/vector2.result +++ b/mysql-test/main/vector2.result @@ -304,3 +304,15 @@ test.t optimize note Table does not support optimize, doing recreate + analyze i test.t optimize status OK insert into t select * from t; drop table t; +# +# MDEV-35230 ASAN errors upon reading from joined temptable views with vector type +# +create table t (f vector(1)); +insert into t values (0x30303030),(0x31313131); +create algorithm=temptable view v as select * from t; +select v1.f from v v1 natural join v v2; +f +0000 +1111 +drop view v; +drop table t; diff --git a/mysql-test/main/vector2.test b/mysql-test/main/vector2.test index c1c70205bb1..a566c898bef 100644 --- a/mysql-test/main/vector2.test +++ b/mysql-test/main/vector2.test @@ -236,3 +236,13 @@ delete from t limit 1; optimize table t; insert into t select * from t; drop table t; + +--echo # +--echo # MDEV-35230 ASAN errors upon reading from joined temptable views with vector type +--echo # +create table t (f vector(1)); +insert into t values (0x30303030),(0x31313131); +create algorithm=temptable view v as select * from t; +select v1.f from v v1 natural join v v2; +drop view v; +drop table t; diff --git a/sql/sql_type_vector.cc b/sql/sql_type_vector.cc index 756c6ad72a9..6a5c698eb96 100644 --- a/sql/sql_type_vector.cc +++ b/sql/sql_type_vector.cc @@ -243,8 +243,8 @@ int Field_vector::reset() static void do_copy_vec(const Copy_field *copy) { - uint from_length_bytes= 1 + (copy->from_length > 257); - uint to_length_bytes= 1 + (copy->to_length > 257); + uint from_length_bytes= static_cast(copy->from_field)->length_bytes; + uint to_length_bytes= static_cast(copy->to_field)->length_bytes; uint from_length= copy->from_length - from_length_bytes; uint to_length= copy->to_length - to_length_bytes; uchar *from= copy->from_ptr + from_length_bytes; @@ -268,7 +268,8 @@ Field::Copy_func *Field_vector::get_copy_func(const Field *from) const { if (from->type_handler() != &type_handler_vector) return do_field_string; - if (field_length == from->field_length) + if (field_length == from->field_length && + length_bytes == static_cast(from)->length_bytes) return do_field_eq; return do_copy_vec; }