Skip to content

Incorrectly insert invalid float value NaN #29015

@wshwsh12

Description

@wshwsh12

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

use test;
create table t(a double);

Run the following golang code:

package main

import (
    "database/sql"
    _ "github.com/go-sql-driver/mysql"
    "log"
    "math"
)

func main() {
   db, err := sql.Open("mysql",
     "root:@tcp(127.0.0.1:4000)/test")
   if err != nil {
     log.Fatal(err)
   }
   defer db.Close()

   prepareStmt, err := db.Prepare("insert into t values(?)")
   if err != nil {
     log.Fatal(err)
   }

   var fo uint64 = 0xFFF0000000000001
   f := math.Float64frombits(fo)
   _, err = prepareStmt.Exec(f)
   if err != nil {
     log.Fatal(err)
   }
}

We should prohibit inserting Nan into TiDB in any way.

2. What did you expect to see? (Required)

Error 1264: Out of range value for column 'a' at row 1

3. What did you see instead (Required)

4.0

[tidb]> select * from t;
+------+
| a    |
+------+
|  NaN |
+------+
1 row in set (0.001 sec)

master

[tidb]> select a, a = 0, hex(a) from t;
+------+-------+------------------+
| a    | a = 0 | hex(a)           |
+------+-------+------------------+
|    0 |     0 | 8000000000000000 |
+------+-------+------------------+
1 row in set (0.001 sec)

hex(a) = 8000000000000000 and it is NaN

4. What is your TiDB version? (Required)

4.0 , 5.0, master

Metadata

Metadata

Assignees

Labels

affects-4.0This bug affects 4.0.x versions.affects-5.0This bug affects 5.0.x versions.affects-5.1This bug affects 5.1.x versions.affects-5.2This bug affects 5.2.x versions.severity/majorsig/sql-infraSIG: SQL Infratype/bugThe issue is confirmed as a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions