Skip to content

Commit d0c6889

Browse files
committed
MDEV-37055 UBSAN: 32801 is outside the range of representable values of type 'short'
avoid overflows caused by float precision loss
1 parent 01c2f6c commit d0c6889

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

mysql-test/main/vector2.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,4 +461,11 @@ delete from t;
461461
insert into t values (0x31313131);
462462
delete from t;
463463
drop table t;
464+
#
465+
# MDEV-37055 UBSAN: 32801 is outside the range of representable values of type 'short'
466+
#
467+
create table t1 (v vector (1) not null,vector index (v));
468+
insert into t1 values (0xf0a08080);
469+
insert into t1 values (0xfa000000);
470+
drop table t1;
464471
# End of 11.8 tests

mysql-test/main/vector2.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,5 +339,12 @@ delete from t;
339339
insert into t values (0x31313131);
340340
delete from t;
341341
drop table t;
342+
--echo #
343+
--echo # MDEV-37055 UBSAN: 32801 is outside the range of representable values of type 'short'
344+
--echo #
345+
create table t1 (v vector (1) not null,vector index (v));
346+
insert into t1 values (0xf0a08080);
347+
insert into t1 values (0xfa000000);
348+
drop table t1;
342349

343350
--echo # End of 11.8 tests

sql/vector_mhnsw.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ struct FVector
100100

101101
FVector *vec= align_ptr(mem);
102102
vec->scale= scale ? scale/32767 : 1;
103+
if (std::round(scale/vec->scale) > 32767)
104+
vec->scale= std::nextafter(vec->scale, scale > 0 ? FLT_MAX : -FLT_MAX);
103105
for (size_t i= 0; i < vec_len; i++)
104106
vec->dims[i] = static_cast<int16_t>(std::round(get_float(v + i) / vec->scale));
105107
vec->postprocess(vec_len);

0 commit comments

Comments
 (0)