From 3436bd69ec0194229a26b6ff8df13abc5c152319 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 17 Aug 2026 17:24:31 +1000 Subject: [PATCH] MDEV-40486 [to-squash] Move the new lneght check in Item_func_vec_fromtext::val_str to later This fixes the crashes mentioned in the parent commit --- mysql-test/main/vector2.result | 10 +++++++++- mysql-test/main/vector2.test | 6 ++++++ mysql-test/main/vector_utf16.result | Bin 425 -> 469 bytes sql/item_vectorfunc.cc | 6 ++---- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/mysql-test/main/vector2.result b/mysql-test/main/vector2.result index 3974af1814e..789dc3a8dae 100644 --- a/mysql-test/main/vector2.result +++ b/mysql-test/main/vector2.result @@ -592,7 +592,15 @@ SELECT VEC_FROMTEXT(concat('[1', repeat(',1', 16382), ']')) AS f; DROP TABLE tt; CREATE TABLE tt AS SELECT VEC_FROMTEXT(concat('[1', repeat(',1', 16383), ']')) AS f; -ERROR 22007: Incorrect vector value: '\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00...' for column `test`.`tt`.`f` at row 1 +ERROR 22007: Truncated incorrect vector value: '[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,...' +CREATE TABLE t1 (v VECTOR(2)); +INSERT INTO t1 VALUES (VEC_FROMTEXT(CONCAT('[1.', REPEAT('0',70000), ',2]'))); +DROP TABLE t1; +SELECT VEC_FROMTEXT('😀😀😀'); +VEC_FROMTEXT('😀😀😀') +NULL +Warnings: +Warning 4038 Syntax error in JSON text in argument 1 to function 'VEC_FromText' at position 1 ## "Zero-dimensional" argument, no change in behaviour after fix SELECT VEC_FROMTEXT('[]') as f; f diff --git a/mysql-test/main/vector2.test b/mysql-test/main/vector2.test index 1cbb377a6bd..7ef042d49df 100644 --- a/mysql-test/main/vector2.test +++ b/mysql-test/main/vector2.test @@ -482,6 +482,12 @@ DROP TABLE tt; CREATE TABLE tt AS SELECT VEC_FROMTEXT(concat('[1', repeat(',1', 16383), ']')) AS f; +CREATE TABLE t1 (v VECTOR(2)); +INSERT INTO t1 VALUES (VEC_FROMTEXT(CONCAT('[1.', REPEAT('0',70000), ',2]'))); +DROP TABLE t1; + +SELECT VEC_FROMTEXT('😀😀😀'); + --echo ## "Zero-dimensional" argument, no change in behaviour after fix SELECT VEC_FROMTEXT('[]') as f; --error ER_TRUNCATED_WRONG_VALUE diff --git a/mysql-test/main/vector_utf16.result b/mysql-test/main/vector_utf16.result index 2e493dc30051fb19012c4f8aef306a6f448d50ca..24d6977beb0ad0a3eb721be4a33f5943dc8ba8e0 100644 GIT binary patch delta 62 ocmZ3!iThsx06anph5!Hn delta 26 icmcc0ypnlB5szP}j}KRIYEEi$iNfRtM*E2`-v9u8FA6aL diff --git a/sql/item_vectorfunc.cc b/sql/item_vectorfunc.cc index 108dd1414f6..a71ee25379b 100644 --- a/sql/item_vectorfunc.cc +++ b/sql/item_vectorfunc.cc @@ -210,9 +210,6 @@ String *Item_func_vec_fromtext::val_str(String *buf) if ((null_value= !value)) return nullptr; - if (value->length() > max_length) - return nullptr; - buf->length(0); buf->set_charset(&my_charset_bin); CHARSET_INFO *cs= value->charset(); @@ -262,7 +259,8 @@ String *Item_func_vec_fromtext::val_str(String *buf) if (!end_ok) goto error_format; - if (Type_handler_vector::is_valid(buf->ptr(), buf->length())) + if (buf->length() <= MAX_FIELD_VARCHARLENGTH && + Type_handler_vector::is_valid(buf->ptr(), buf->length())) return buf; null_value= true;